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:
“Hey Dmitry,
Could you please add Kirk Munro, Darin Pendergraft, Oleg Shevnin to the PowerGUI DL?
Thanks!“
All you need to do, is copy the part of the email with the names, use PowerShell -split operator to break it by comma characters, and pipe the result into Add-QADGroupMember:
'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:
'Kirk Munro
Darin Pendergraft
Oleg Shevnin' -split "`n" | Add-QADGroupMember PowerGUI
And by the way, email addresses instead of user names are totally fine too:
'user1@domain.my, user2@domain.my' -split "," | Add-QADGroupMember PowerGUI
One of those cases when command line is so much easier than UI.