How to add all users in an Active Directory OU to a group using powershell (like a sophisticated person would do).

If you want to feel really sophisticated you can do this. It’s very easy. I’ll show you how.

** Replace with the OU searchbase and group name (Office1_N_Drive is group name here in this example) **

get-aduser -searchbase 'OU=Users,OU=Office1,OU=Offices,DC=domain,DC=local' -Filter * | % {Add-ADGroupMember 'Office1_N_Drive' -Members $_} -verbose    

In the above example, we have a domain name “domain.local” . There is an OU named “offices”, within that OU is an ou named “Office1” , and within THAT OU is an OU named “users”

In this particular instance, the true OU and domain names have been obfuscated, but Office1_N_Drive (mapped drive) access permissions were controlled by that group, and we had wanted all the users in that OU to be given permission quickly and easily. This did the trick.

Now you too have what it takes to be sophisticated.

Happy Powershelling.

Leave a Comment