Find All Office 365 Group Memberships of a User using PowerShell

Requirement: Get a list of all Microsoft 365 groups where a particular user is a member (or owner!).

How to a Find a Particular User’s All Microsoft 365 Groups Membership?

We wanted to find out what Office 365 group memberships a user has. To find out all Microsoft 365 group memberships of a user, do the following:

  • Login to Microsoft 365 Admin Center https://admin.microsoft.com
  • Under the “Users” tab, search and find the user you are interested in.
  • Click on the user name to open user properties >> In the user properties pane, click on “Manage groups” under “Groups”find all the office 365 groups a user is a member of with powershell
  • This gets you all Office 365 groups a user is a member of.find all microsoft 365 groups users is member of

PowerShell to Find Users Microsoft 365 Group Memberships

Now, let’s use PowerShell to retrieve the group memberships of a given user.

Prerequisites: Install AzureAD PowerShell Module

You must have the AzureAD PowerShell module. This script installs AzureAD PowerShell module if it’s installed in your system already. Make sure you are running this as an administrator!

#Check if AzureAD Module is installed
$AzureAD = (Get-Module AzureAD -ListAvailable).Name

Try {
    If ($AzureAD -eq $null) 
    {
        Write-host "AzureAD module is unavailable! Installing AzureAd module..." -f Yellow

        #Install AzureAD Module
        Install-Module AzureAd -Allowclobber -Repository PSGallery -Force
        Write-host "AzureAD Module installed to your machine Successfully!" -f Green
    }
    Else { 
        Write-host "AzureAD Module is already installed in this system!" -f Yellow
    }
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
}

Once we have the AzureAD PowerShell module installed, use this PowerShell script to find all Microsoft 365 groups where a user is a member and export the data to CSV file.

Import-Module AzureAd -ErrorAction SilentlyContinue

#Parameters
$UserID = "[email protected]"
$CSVFile = "C:\Temp\GroupMemberships.csv"

Try {
    #Connect to Azure AD
    Connect-AzureAD -Credential (Get-Credential) | Out-Null

    #Get the User
    $User = Get-AzureADUser -ObjectId $UserID

    #Get User's Group Memberships
    $Memberships = Get-AzureADUserMembership -ObjectId $User.ObjectId | Where-object { $_.ObjectType -eq "Group" }

    #Export group memberships to a CSV
    $Memberships | Select DisplayName, Mail, ObjectId | Export-Csv -LiteralPath $CSVFile -NoTypeInformation
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
} 

Please note, this script gets all the Microsoft 365 group memberships of a given user, doesn’t matter if he’s added as a member or owner of the group.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply