Solved

Add multiple users to AD group with Powershell

Posted on 2014-10-01
8
586 Views
Last Modified: 2014-10-04
Hi EE

Can someone school me on a better way of adding multiple users to an AD group ? the script below seems to take along time.
Wondering what others are using ..



Foreach ($User in GC C:\PS\Users.txt){
GC C:\PS\groups.txt | % {
Add-ADGroupmember -identity $_ -member $User
	}
}

Open in new window

0
Comment
Question by:MilesLogan
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40356090
$users = GC C:\PS\Users.txt
GC C:\PS\groups.txt | % {
$gname = $_
$users | % {Add-ADGroupmember -identity $gname -member $_}
      }
0
 
LVL 40

Expert Comment

by:footech
ID: 40356119
You can specify an array for the -members parameter of Add-ADGroupMember.
$Users = GC C:\PS\Users.txt
GC C:\PS\groups.txt | % {
Add-ADGroupmember -identity $_ -members $Users
}

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 40356133
This will work ! thank you
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:footech
ID: 40356165
I haven't tested, but I would be highly surprised if becraig's performs any different than what you originally posted.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40356172
So Footech you think multiple reads from disk will have the same overhead as looping through an array ?
0
 
LVL 40

Expert Comment

by:footech
ID: 40357042
No, you're absolutely right. The single read will definitely be faster.  For some reason I was only focused on the multiple calls to Add-ADGroupMember.  But now you've got me curious about the relative speed of the disk read vs. the AD call.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40357092
Incidentally I think your approach is faster single ad call against the array.

I just provided one solution slightly faster than the author had initially been using.
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 40361118
Thanks guys , I appreciate the additional comments .. You both are awesome 🙆!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

In-place Upgrading Dirsync to Azure AD Connect
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
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.

726 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