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'.

link|improve this question

40% accept rate
feedback

2 Answers

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.

link|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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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