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
MVP
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 Rote
Oct 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.
- Patrick RoteOct 02, 2020Iron ContributorThanks that actually did work .
Although i found out i could loop through the members too