Say, you get an email asking to add a bunch of members to a distribution list you manage. What is the easiest way to do this? Going to Outlook, making 5 clicks to get to the dialog box, and then manually adding each user from the address book picker is definitely not fun. However, PowerShell definitely is.
I’ve seen people submitting lists of members to add in a couple of ways: separated by commas (or semicolons) or each on a separate line. Both would work fine – the only difference is how you would tell PowerShell to split this string into actual members’ names.
Let’s start with a comma-separated list. Like this:
Could you please add Kirk Munro, Darin Pendergraft, Oleg Shevnin to the PowerGUI DL?
'Kirk Munro, Darin Pendergraft, Oleg Shevnin' -split "," | Add-QADGroupMember PowerGUI
That is it!
Line by line option is not much different – you just have to split by newline character (
"`n") instead of comma:
Oleg Shevnin' -split "`n" | Add-QADGroupMember PowerGUI
And by the way, email addresses instead of user names are totally fine too:
'firstname.lastname@example.org, email@example.com' -split "," | Add-QADGroupMember PowerGUI
One of those cases when command line is so much easier than UI.🙂