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:

image

Script

image

 


I have also uploaded this script to Microsoft TechNet Gallery - http://gallery.technet.microsoft.com/scriptcenter/ffff189d-8ef1-4903-b19c-12dcd352c88e

More Scripts -  http://portal.sivarajan.com/search?q=scripts&x=0&y=0

12 comments:

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

Hi,

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

Needz

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.

richard-lee-morris,

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
}

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More