My PowerShell

Windows Powershell scripts, examples, tips, docs …

Add Users to AD Group

Sometimes managing groups in Active Directory becomes tedious and even overwhelming. Sure, you can add a user to multiple groups using Active Directory Users and Computers (ADUC), but imagine if you need to add 100 users into a group… Powershell can make this task very easy.

Input file (MyUsers.csv) contains samAccountName in the following format:

UserName
user1
user2
user3
user4
....

Import-module ActiveDirectory

Import-CSV “C:\MyScripts\MyUsers.csv” | % {
Add-ADGroupMember -Identity MyGroup1 -Member $_.UserName }

Then you can check (export users list) who belongs to that Group:

Get-ADGroupMember MyGroup1 | export-csv c:\MyScripts\ExportedUsers.csv

Tagged as:

Leave a Response