Friday, July 29, 2011

Add Users to a Group–PowerShell Script

Purpose – Add users to a group from an input file – PowerShell V2 Script. 

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





I have also uploaded this script to Microsoft TechNet Gallery -

More Scripts -


This comment has been removed by the author.

net localgroup command is also equally simple and easy to use.
refer add user to group

Hi Santhosh,

The post is quite a useful one. I am new to this PS scripts, and would like to know, whether it reads our CSV or a text file, and add each users found in the CSV to the AD group, "TestGroup1" as in example. If it runs for a second time, the user already present in the Group, would it still add, or it skips and addthe next user? How does it work?

Thank you it helped me a lot


what about adding users on local server rather than Domain controller ?


very helpful PS script for my application. I needed to add a long list of domain users into several admin groups. This script saved me tons of time.


Thanks and appreciate your feedback!

Can you please let me know how can we use the same script to add a user to a secuity group in another trusted domain, This script only works for logged in domain.

thank you for this useful easy article.

Excellent script quick question though I have AD groups which are long and are separated eg BR-Systems Support the script doesn't like the space between Systems and Support

You have a few options. Try with "GroupName" "BR-Systems Support "

Other option is to define a variable with your group name.

Import-module ActiveDirectory
$GroupName = "BR-Systems Support"
Import-CSV "C:\Scripts\Users.csv" | % {
Add-ADGroupMember -Identity $GroupName -Member $_.UserName

I still get an error as following ( using email adress and just the initial and last name ) still errors !

Add-ADGroupMember : Cannot find an object with identity

This comment has been removed by the author.
This comment has been removed by the author.

Try this:
Import-module ActiveDirectory
Import-CSV C:\Scripts\Users.csv | % {Add-ADGroupMember -Identity GroupName -Member $_.UserName}

without the Quotation Marks and for GroupName use your own groupname you need to use.

Chears, John

Post a Comment

Popular Posts


Twitter Delicious Facebook Digg Stumbleupon Favorites More