Here’s a one-liner to turn members of a group into a list of email addresses, separated by semicolon. I am using it every now and then when someone from our partners (which obviously do not have access to our address book) ask me for a list of folks to include in some discussions, or grant access to some resources, and so on.
Here’s the oneliner (for PowerShell v2):
(Get-QADGroupMember MyGroupName -Type user -Indirect | Select -expand Email) -join ';'
PowerShell v1 version has a slightly different syntax for join:
[string]::join(';', (Get-QADGroupMember MyGroupName -Type user -Indirect | Select -expand Email))
And here’s a quick explanation of what it does:
- I use
Get-QADGroupMemberto retrieve all members of the group. Note that-Indirectparameter gives me all members of nested groups, and-Type usermakes sure that nested groups themselves get excluded. - Then I am taking the collection of user objects and turn that into a collection of just one property of the objects (Email) using
Select -expand. - Finally I am using join to turn that collection into a string and using semicolon as separator.
Hope this is useful.
Subscribe by email




0 Responses to “Get a list of users’ email addresses”