?
Solved

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

Posted on 2016-10-17
3
Medium Priority
?
26 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

850 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