?
Solved

Add multiple users to AD group with Powershell

Posted on 2014-10-01
8
Medium Priority
?
611 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 2000 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
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

Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

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