[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2016-10-17
3
Medium Priority
?
25 Views
Last Modified: 2016-11-05
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.
0
Comment
Question by:P S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Muhammad Mulla earned 1000 total points (awarded by participants)
ID: 41846450
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 $_.group}

Open in new window

0
 
LVL 19

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 1000 total points (awarded by participants)
ID: 41846578
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

1
 
LVL 10

Expert Comment

by:Muhammad Mulla
ID: 41875272
Solution should work as proposed.
0

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question