Forum Discussion
Patrick Rote
Oct 01, 2020Iron Contributor
How to get all users exported from an AD AzureGroup listing their,email addresses?
Hi All, How to get all users exported from an AD AzureGroup listing their,email addresses e.g a group starting with "HRUSERS" Do i need to install a module for powershell? Thanks in advance
- Oct 02, 2020
Use the -Append switch for Export-CSV.
VasilMichev
Oct 01, 2020MVP
PowerShell is the best way to do this, you'll need the AzureAD or the MSOnline module. Here's a sample for the former:
Get-AzureADGroup -SearchString GroupName | Get-AzureADGroupMember | select DisplayName,UserPrincipalName | Export-Csv -nti blabla.csv
Patrick Rote
Oct 01, 2020Iron Contributor
VasilMichev Thanks so much for the response.
When i ran the command it worked but how can i add another field showing the actual group name ( e.g something like this
GroupName | DisplayName(This is the name of the user) | UserPrincipleName(Email address)
The searchstring i used is for example is "Test" but there are groups with names Test1,Test 123,Test456
So what i need is something like this :-
GroupName | DisplayName(This is the name of the user) | UserPrincipleName(Email address)
Test1 Peter O po@email
Test123 Michael Dunns md@email
Is this possible?
Thanks in Advance
- VasilMichevOct 01, 2020MVP
That's a bit more complicated, as in it requires a more convoluted piece of code to fit in a single line.
$groups = Get-AzureADGroup -SearchString TeamOne foreach ($group in $groups) { Get-AzureADGroupMember -ObjectId $group.ObjectId | select @{n="GroupName";e={$group.DisplayName}},DisplayName,UserPrincipalName}
- Patrick RoteOct 02, 2020Iron Contributor
VasilMichev Thanks for the reply,
$groups = Get-AzureADGroup -SearchString TeamOne foreach ($group in $groups) { Get-AzureADGroupMember -ObjectId $group.ObjectId | select @{n="GroupName";e={$group.DisplayName}},DisplayName,UserPrincipalName Export-Csv -nti GetTestGroupMembers.csv }
I tried adding an export function to it like above but it seems i'm only getting the fist group on the list.
But i can see that you are looping through all the groups.
Am i missing something.I need it to export all the groups in the list to the csv
Thanks in Advance
- VasilMichevOct 02, 2020MVP
Use the -Append switch for Export-CSV.