Solved

Add multiple users to AD group with Powershell

Posted on 2014-10-01
8
599 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Here's a look at newsworthy articles and community happenings during the last month.
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 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.

691 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