Solved

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

Posted on 2016-10-17
3
15 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:A D
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Muhammad Mulla earned 250 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 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 250 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 9

Expert Comment

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

Join & Write a Comment

Suggested Solutions

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
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…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now