?
Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

801 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