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

92 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
}

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

Hi, is there a way to also specify the group that each user is a member of in the CSV file and the script will add it accordingly? So there would be multiple users added to multiple groups. Can I also specify a security group under the UserName column in the CSV? Sometimes we have a security group that's a member of another group. Thanks for the help!

Hi, is there a way to also specify the group that each user is a member of in the CSV file and the script will add it accordingly? So there would be multiple users added to multiple groups. Can I also specify a security group under the UserName column in the CSV? Sometimes we have a security group that's a member of another group. Thanks for the help!

Hi Santosh,
I have to add approx 5000 users in one single AD group, i tried it your way but i couldn't do that.
i am getting this error (Add-ADGroupMember : Cannot find an object with identity).
Could you please help me into this ?.

How do i other domain users ? Like if group domain is america and you want to add a user from asia how to do it? By default it is searching the user in the group's domain

There is a typo in the script -member should be -members . Or Microsoft added an s to it in later versions

I'm getting an error when trying to run this.
Here is the script I'm using.

Import-CSV "C:\Users.csv" | % { Add-ADGroupMember -Identity Domain Users -Members $_.UserName }

The CSV file I'm using has the header UserName and the first name is Chase Chapin.

The error seems to be pointing to the CSV file. I'm putting the first error here, since they all seem to be the same.

Add-ADGroupMember : A positional parameter cannot be found that accepts argument 'Users'.
At line:1 char:33
+ Import-CSV "C:\Users.csv" | % { Add-ADGroupMember -Identity Domain Users -Member ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

Thank you,
Dave


Param(
[string] $group # List of servers that needs to be checked. Has to a text file!
)

$UsersCSV = Import-Csv "C:\script\adgroup\adgroup.csv" | select -ExpandProperty identity
#$list = Get-Content $UsersCSV

foreach ($user in $UsersCSV)
{
$u = (Get-ADUser -Identity $user).distinguishedName
$g = Get-ADGroupMember -Identity $group | select -ExpandProperty distinguishedname

If ($g -contains $u ) {
Write-Host " $user already exists in this group" >> result.txt
}
Else {
Add-ADGroupMember $group -Members $u
Write-host " $user added to group successfully” >> result.txt
} }

Where can I go to find out more about powershell. I've never used it before and now it's become increasingly important that we all know how to use it...



If you are looking for luxurious Handbags bearing designer labels, Vitapress.By is the destination to visit. It is a website where you will find genuine leather Louis Vuitton Bags of luxury handbags from famed brands like Balenciaga, Celine, Dior,Hermes handbags, Fendi and Saint Laurent among others. And the sale price and high quality has won a great reputation all over the world.Also ,The Rolex Watches It offers free shipping for all orders and countries.






تسليك مجارى بالاحساء تسليك مجارى بالاحساء
تسليك مجارى بالدمام تسليك مجارى بالدمام
تنظيف بيارات بالرياض تنظيف بيارات بالرياض

كشف تسربات المياه بالاحساء كشف تسربات المياه بالاحساء

There are academic nursing writing help companies whose ultimate goal is to provide Help with Nursing Writing Services since they are aware most nursing essay writing service part-time students lack enough time to complete their college custom nursing assignments.

Online logistics research paper writing help has become very popular among students seeking Logistics Writing Services Online and logistics and supply management essay writing services.

Online e-commerce essay writing help services are very common nowadays since there are very many students seeking E-commerce Essay Writing Services and e-commerce research paper writing services.

Business coursework writing services are essential for business assignment writing services and Business Essay Writing Services seekers.

Thanks for sharing it is important for me. I also searched for that from here. Visit our site panda helpdesk telefoon

That’s a nice article, thank you for a great article. It helped me a lot. Keep it up Must Visit panda contact belgie

Really Nice Post Admin, Very helpful looking for more posts, Now I have to share some information about How To Fix “Lenovo Troubleshooting Guide” problem. If you are going through this problem you can simply visit Lenovo ondersteuning

Really Nice Post Admin, Very helpful looking for more posts, Now I have to share some information about How To Fix “yahoo mail Troubleshooting Guide” problem. If you are going through this problem you can simply visit yahoo mail bellen

hi, your post is very helpful for me. Finally, I found exactly what i want. If you need information regarding antivirus then you can visit our site Lenovo ondersteuning belgie

Really Nice Post Admin, Very helpful looking for more posts, Now I have to share some information about How To Fix “Bullguard Troubleshooting Guide” problem. If you are going through this problem you can simply visit Servicio al cliente Bullguard

Don’t think you can’t do this because you can do this easily when you are going to make your boring life into the most romantic and hot life with the company of Dharamshala Escorts.
Dehradun Escorts
Dehradun Escorts

Nice article and very useful thanks for share with us.
Visit Our Websites:-
Ahmedabad Escorts
Ahmedabad Escorts
Ahmedabad Escorts

Ultimate Destination for finding High Profile Independent Escorts in Nainital Like You Feel 100 % Real Girl Friend Experience.
Nainital Escorts | Nainital Escorts

Take Indian High Profile Trusted Delhi Escorts Services
We are famous among personalities in Delhi city direct pay the hand payment Delhi Escorts Services and Direct Deal With Our Girl at your place or my Escort In Delhi.
Delhi Escort
Delhi Escorts

I also have an agency of designer sleepwear to tempt my soul. it's tough to say with this truth that the majority in Borivali is eager to go back to the city. Hospice is an incredible vacation region. It's one of these objectives that go back right here, Delhi Escorts girls to offer them a reputation for attractiveness and confirm that they need a horrible time.

If You are Looking For Escorts Service in Your City? Ascorts Club Escorts Agency - Who Provide Independent Call Girls, Model Escort,
Celebrity Escort and More Kind Escorts Girls in India. Just Call us and Book Your Dream Girl.

Ascorts Club Escorts Thane
Ascorts Club Escorts Bandra
Ascorts Club Escorts Juhu
Ascorts Club Escorts Lokhandwala

Welcome to Best Jaipur Escorts Service and Call Girls Agency. Call anytime To Book Female Escorts in Jaipur, Escort Girls Available 24/7.
Jaipur Call Girls

We are the best and profoundly clandestine office that has been giving agency In Haridwar Escorts for quite a while. We are known not to frustrate anybody so visit our site.

Haridwar Escorts

Many of these people are beautiful, stunning, and professional, and they want to date you and meet your needs in Haridwar Escorts so contact us.

Haridwar Escorts

Our Call girl provider In Kalkaji Escorts will be your friend and your darlings. Simply pick a young lady that meets your requirements and we will ensure you get what you anticipate so contact us we are here for you.

Kalkaji Escorts

Kalkaji Escorts Service

You can have a wide range of fun delights with great Haridwar Escorts from all around the globe So on the off chance that you also have any unfulfilled wants need wedding night experience, single man gathering, or birthday celebration festivities, simply call our site and discover the delights of paradise directly close to you.

Haridwar Escorts

Haridwar Escorts Service

Hey, Guys, I'm Neha Sharma, a model call girl in Cuttack Escorts. If you are looking for Russian call girls so visit our site and contact us because we are a night service provider and we are here for you.

Cuttack Escorts

You ought to choose first which one out of these three, you might need to attempt in Kalkaji Escorts. Those three primary fun positions are- female commanding fun Positions:- where the female accomplice overwhelms the male accomplice and does the greatest pieces of the sexual activities exercises.

Kalkaji Escorts

Kalkaji Escorts Service

Bedroom experience is a must for the clients when they are thinking of getting the paid services of escorts. You can cultivate bedroom experience by getting hookups from Malviya Nagar Escorts.

Malviya Nagar Escorts

Hey Guys I'm Neha Sharma and sexy call girl in Haridwar Escorts. if you are looking for model escorts so visit our site and contact us because we are the sexual activity service provider and we are here for you.

Haridwar Escorts

Check in the luxury hotel to explore the joy of nailing a sexy girl escort in Cuttack. Hire our Cuttack Escorts service to enjoy your nights on Odisha Trip.

Cuttack Escorts

Coimbatore is not the only destination we reach instead you can appoint our best call girls service in Chennai as well. We are Coimbatore Escorts agency since 2010.

Coimbatore Escorts

Enjoy these amazing sex positions With Haridwar Escorts to fulfill your desire practically all you love to have intercourse and need to feel the excellence of this astonishing robust involvement.

Haridwar Escorts

Relationships are the most amazing things for men and when you are thinking to ensure the bold relationship possibilities for romantic hookups then you must connect with the services of Pathankot Escorts.

Pathankot Escorts

Pathankot Escorts

Pathankot Escorts

A Seductive night is mainly related to hot things. On a seductive night, you can enjoy sexy things with your partner, and Haridwar Call Girls is the right choice for the clients to ensure these things.

Haridwar Escorts

Haridwar Escorts Service

Russian Escorts mean you are going to book the premium material for sex in your life. It would help if you availed yourself of the premium things for the physical relationship goals so contact us.

Rajouri Garden Escorts

Rajouri Garden Escorts Service

Without a doubt, you may have your time any way you want with the top dates and stunning Pathankot Escorts available online. You can enjoy this fantastic experience wherever you choose.

Pathankot Escorts

Pathankot Escorts Service

Coimbatore is not the only destination we reach instead you can appoint our best call girls service in Chennai as well. We are Coimbatore Escorts agency since 2010 so contact us.

Coimbatore Escorts

Coimbatore Escorts Service

We know that various individuals visit Independent Delhi Escorts, for potential employee meetings, administration, etc. You can contact our maintenance administration at any time; Pooja for your service. We are free 24 hours a day. That way, it's possible to reach out to us when you feel you need more joy and satisfaction in your daily life. As the night progresses, our maidens will keep you running and lighting up the whole day. We have Delhi Escorts, you can't find anywhere else.

By then, he should wrinkle the legs in a vertical mountain shape. Starting there onward, the Rajouri Garden Escorts fun girl should sit over the male associate and you want to enjoy so visit our site.

Rajouri Garden Escorts

Rajouri Garden Escorts Service

When making a decision for oneself, there are a few factors to consider. Coimbatore Escorts look at a variety of options, doesn't be rushed, and makes a decision. Check through the customer reviews to verify if you've arrived at the proper spot.

Coimbatore Escorts

Coimbatore Escorts Service

Thank you so much for sharing this post, I appreciate your work. It was a great informative post. Go so many useful and informative links. Loved your writings also.
makeup artist course
self makeup course
professional makeup courses
The Real Science

Thank you so much for sharing this post, I appreciate your work. It was a great informative post. Go so many useful and informative links. Loved your writings also.
Salon in Dwarka
Best salon In Delhi

Thank you so much for sharing the informative post, I appreciate your work. Go so many useful and informative links. Loved your writings also.
Best Makeup Artist Dwarka
Best Makeup Artist

In whichever place you wish to have the presence of the babes here at our Pune Escorts agency, they can be adjusted to any place.
VIP Independent Pune Escorts
call Girls in Pune
Pune Escort Service
Pune Escorts Agency

It would be some of the incredible moments of love and erotic fun with these passionate skilled partners over here.
CNN-News18 escorts in Chandigarh
Chandigarh escort service Arise News

You can always be in advantageous position being linked to all of these horniest darlings here.
NewsNation Chandigarh escorts
TVB iNews escort service Chandigarh

Hot Vip call girls in Ambala In any of the particular locations you wish to be linked to the well developed babes here with us, they are mostly adjustable to any environment.

High profile Ambala Escort Service
VIP high profile Ambala Escorts
High Profile Ambala call girls

The Escorts in City can remain engaged to anyone owing to their skills and commitments all around.
Chandigarh escort Brigada News TV
escort service in Chandigarh ARY News

The clients are seriously going to select the options from our escort agency leaving the others in the entire list.
Apna News Chandigarh escorts service
ABP News Chandigarh escorts service

VIP Model Independent call girls in Mussoorie are therefore selected to be involved in the session of love giving their clients some incredible minutes of erotic romance.

VIP Independent mussoorie Escorts
mussoorie Call Girls
High Profile Call Girls in Mussoorie

Call girl Red Light Area in Chandigarh who may be an impressive model, the model who is really charming, sensual, lively and enticing.

Call Girls Red Light Area in Chandigarh Escorts Girls Services

Amritsar Escort service have all sorts of skills in meeting the desires of men whenever they require. It is fine characteristics of these ravishing hot babes which is going to call out clients from all parts of this world.
Follow us:-

Hi Profile Call Girls in Amritsar
Amritsar Escorts Service
Amritsar Escorts
Amritsar Call Girls
Russian Escorts Service in Amritsar

Dehradun call girls are the most promising associates here to be appointed in for the session of romance. They do have the best of skills in eliminating all kinds of depressions from the minds of men.
Follow us:-

Dehradun Escorts
Dehradun Escorts Service
Call Girls in Dehradun
Dehradun Escorts Service

Appoint Call Girls in Jammu to different programs .Whether the kind of occasion is an official meeting, corporate event or some other special program, the divas here do have patience to handle all customers.Follow us:-
Follow us:-

Jammu Escorts Service
Jammu Escorts
Jammu Escorts Service
Jammu Escorts
Jammu Escorts Service
Jammu Escorts
Jammu Escorts Service

Zirakpur call girls are suppose to perform well being linked with their clients owing to their wide range of experience and knowledge.
Follow Us:-

Zirakpur Escorts
Zirakpur Escorts Service
Zirakpur Escorts
Zirakpur Escorts
Zirakpur Escorts Agency
Zirakpur Escorts
Zirakpur Escorts

The Call Girls in Panchkula are therefore termed to be the best of all in the entire list who can easily get away all your pressures and troubles of personal lives.
Follow Us:-

Escorts Service in Panchkula
Panchkula Escorts
Call Girls in Panchkula
Panchkula Escorts
Panchkula Escorts
Panchkula Escorts Agency

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More