Download group members with groups they belong to (AAD)

Copper Contributor


Just like in topic - I need to download list of users from AAD with groups they belong to, for example:

Group A has users X, Y and Z and X is a member of group 1, Y - 1 and 3, Z - 2, 3. I need a list of them with their groups.

I always used script below to get users from group but I dont have any idea to create script which will help me complete my sentence.


$GroupName = Read-Host -Prompt "Enter group name: "
$Groups = Get-AzureADGroup -SearchString $GroupName
$GroupCount = $groups | measure
$Count = $groupCount.Count

$GroupMembers = foreach($Group in $Groups){
$GroupID = $Group.ObjectId
$GroupName = $Group.DisplayName
Write-Progress -Activity "Groups found: $Count`
Group name: $GroupName"
Get-AzureADGroupMember -ObjectId $GroupID | Select-Object -Property @{Name = 'GroupName'; Expression= {$GroupName}}, UserPrincipalName

$GroupMembers | Export-Csv C:\PSData\AADGroup.csv


I hope I explained everything correctly. :)

1 Reply
best response confirmed by SS_9711 (Copper Contributor)
Try the script here:
It takes input as a list of users, so you can feed it the group A membership:

.\AAD_Groups_MemberOf_inventory.ps1 -UserList (Get-MgGroupMember -GroupId $GroupID).UserPrincipalName