Knowing which groups a user is a member of is essential for access control, compliance, and troubleshooting. While Microsoft Graph PowerShell's Get-MgUserMemberOf cmdlet can help retrieve this information, it comes with the usual challenges of scripting—complex syntax, elevated permissions, and limited report formatting options.
Before using the Get-MgUserMemberOf cmdlet:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.Read.All", "Group.Read.All"
This cmdlet lists the groups that a specific user is a direct member of:
Get-MgUserMemberOf -UserId "john@zkyy.com"
Example 1: List group memberships for a single user
Get-MgUserMemberOf -UserId "jane@zkyy.com"
Example 2: Filter group memberships by type (e.g., Security)
Get-MgUserMemberOf -UserId "Ash@zkyy.com" | Where-Object {$_.AdditionalProperties.'@odata.type' -eq "#microsoft.graph.group"}
Example 3: Export group memberships to CSV
Get-MgUserMemberOf -UserId "Tessa@zkyy.com" | Select-Object Id, DisplayName | Export-Csv -Path "group-memberships.csv" -NoTypeInformation
| Parameters | Description |
|---|---|
| -UserId | This parameter is used to specify the unique identifier of the user to fetch group memberships. |
| -All | This parameter retrieves all results. |