Solved

Add multiple users to AD group with Powershell

Posted on 2014-10-01
8
582 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
  • 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 39

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 39

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 39

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

770 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