PowerShell: Add All Members of an OU to a Security Group

KB ID 0001589

Problem

I’ve written in the past about ‘Bulk Adding Users from CSV files, into Groups‘. But what if you want to add ALL users in a particular OU into a security group?

Solution

The syntax is;

Get-ADUser -SearchBase ‘OU=Source-OU,OU=PNL,DC=pnl,DC=com’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘SG-Test-Group’ -Members $_ }

Here I’ve got 20 users that need adding to a group, in this example the group’s in the same OU, but it does not have to be;

Add OU Members to a Security Group

You will need to close and reopen the group properties for it to refresh its membership.

PowerShell Add OU Members to a Security Group

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *