Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Assume I have a distribution group in Exchange which currently exists, and holds about 20 members.

In Powershell 2, I have acquired a list of about seven hundred more individuals who need to be added to the group. The only way I have been able to do this is one user at a time:

Add-DistributionGroupMember -Idneity GROUP-NAME -Member Member1
Add-DistributionGroupMember -Idneity GROUP-NAME -Member Member2
....
Add-DistributionGroupMember -Idneity GROUP-NAME -Member MemberN

Is there a mechanism available that allows me to add all users with just one function call, as represented by the following pseudo-code?

SOME-CMDLET-TO-ADD-LOTS-AT-ONCE -Identity GROUP-NAME -Member COLLECTION-OF-PEOPLE

I'm not looking for loop constructs. I'm looking for a function or cmdlet that can add all members at once, ideally taking only one argument referencing the entire list. I'm scared to think what Powershell would do with 700+ command-line arguments...

(I'm hoping that if this IS possible, that I can pass an array or collection of objects to be added.)

Any suggestions? I don't see a command called 'set-distributiongroupmember', and I also don't see anything promising in 'set-distributiongroup'.

share|improve this question

6 Answers 6

I'm not sure why you don't want to use a loop construct; that's kinda one of the major features of PS. A simple:

Import-CSV FileName.csv | ForEach {Add-DistributionGroupMember -Identity "GROUP-NAME" -Member $_.Name}

would easily do the trick. Failing that, though, there's no cmdlet to do exactly what you want. You could do a

Remove-DistributionGroup GROUP-NAME; New-DistributionGroup -Name GROUP-NAME -Members memberlist

but that's a little cheesy.

share|improve this answer
    
The reason I don't want to use a loop construct is that I have empirical evidence that suggests performing one call to interact with a distribution group is orders of magnitude faster than making the same call to interact with a distribution group hundreds of times. It's about performance, which a loop construct doesn't give me. It's pretty sad and inconsistent that new-distributiongroup lets you specify a list argument, but add-distributiongroup doesn't. –  Larold Sep 28 '11 at 20:54
    
What is this evidence? I'd be curious to see if what you did was a true "apples-to-apples" comparison. I'd like to run the test myself. –  pk. Sep 28 '11 at 21:24
    
Gather a list of 1,000 email addresses. Create mail contacts for them. Then add them to a distribution group one at a time with add-distributiongroupmember. Then, for comparison, make a call to new-distributiongroup with 1,000 of those contacts in the single array argument. Additionally, try calling get-distributiongroupmember one member at a time for a whole group, then try returning everyone at once. In short - every call that connects to AD or Exchange produces significant overhead. That's why I only want one call to add everyone in my array. –  Larold Sep 29 '11 at 1:42
1  
My results: Add-DistributionGroupMember x 1000 : 2m 13s --- New-DistributionGroup $arrayof1000Contacts : 17s = significant enough difference to care –  pk. Sep 29 '11 at 14:15
    
@pk - thanks for confirming. That's why I'm dying for functionality to pass an array to add-distributiongroup, just like you can pass to new-distributiongroup. Definitely something MS should consider in future releases. –  Larold Sep 29 '11 at 14:43

Try this, it seems to work for me:

Get-Content | Add-DistributionGroupMember

Text file just contains the aliases of the users that you want to add.

share|improve this answer

Successfully populated a Distribution Group by creating a text file, populating with member account aliases, then executing the command:

% Get-Content <path\filename.txt> | Add-DistributionGroupMember "<Display Name of Distribution Group>"

See these URLs for further details:

share|improve this answer

It looks like the Quest Active Directory PowerShell Cmdlets can add multiple users to a group at one time per this wiki page. In my brief testing, I was able to use the Add-QADGroupMember cmdlet to add a small array of users to a test group in Active Directory.

share|improve this answer

Not sure why the teams at Microsoft made this so complicated. Sometimes you just have to think simple.

"user1","user2","user3" | Add-DistributionGroupMember -Identity "SomeMailbox"
share|improve this answer

It might be helpful too to add AD with this:

import-module ActiveDirectory

Then just use:

Add-AdgroupMember MyList -member user.alias,user2.alias,user3.alias,...

For this you do need RSAT installed (MS product, and free) or it won't work.

share|improve this answer
    
How does this solve the problem of the manual repetition the OP is interested in avoiding? –  squillman Nov 19 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.