Need a power shell script to add multiple AD objects in a security group

I have a CSV file with multiple servers in it and i have to add  these servers in a security group. Can anyone assist me with a powershell script to complete this task?.

Thanks in advance.
P SAsked:
Who is Participating?
Muhammad MullaConnect With a Mentor Commented:
If you have quest powershell tools installed it can be done like this;

import-csv c:\test.csv | foreach{$_.logonname |add-qadgroupmember -identity "Test Group"}

Open in new window

If the quest tools aren't available, then you could try:

$members = Import-CSV c:\test.Csv -Header group
$members | ForEach-Object {add-Adgroupmember -Identity 'test group' -members $}

Open in new window

Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
small correction in Muhammad's code
replaced members with member    (typing error may be)  

Header name should be ServerName because the csv contains servers.

$members = Import-CSV c:\test.Csv 
$members | ForEach-Object {add-Adgroupmember -Identity 'test group' -member $_.ServerName}

Open in new window

Muhammad MullaCommented:
Solution should work as proposed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.