The Get-MgGroupMember cmdlet in Microsoft Graph PowerShell retrieves the members of a Microsoft 365 group. It can return details about users, service principals, or devices that belong to a group.
Managing group memberships is critical for access control and collaboration in Microsoft 365. With Get-MgGroupMember, administrators can:
Before using this cmdlet, ensure that the Microsoft Graph module is installed and that you’re connected with the proper permissions:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.Read.All"
Syntax (essential parameters):
Get-MgGroupMember -GroupId <GroupId>
You can filter, sort, or limit the results, and even retrieve additional user properties for deeper insights.
Get-MgGroupMember -GroupId "<GroupId>"
Get-MgGroupMember -GroupId "<GroupId>" -Search "displayName:John" -ConsistencyLevel eventual
Get-MgGroupMember -GroupId "<GroupId>" -Top 10
Get-MgGroupMember -GroupId "<GroupId>" -Sort "displayName asc" -ConsistencyLevel eventual -CountVariable groupCount
# Retrieve members of a specified group
$groupMembers = Get-MgGroupMember -GroupId "1cbe8c31-589d-453a-a1e5-045f7f00c967"
# Initialize an array to store detailed user information
$userDetails = @()
# Loop through each group member and retrieve additional properties
foreach ($member in $groupMembers) {
$user = Get-MgUser -UserId $member.Id -Property "id, displayName, userPrincipalName"
$userDetails += [PSCustomObject]@{
Id = $user.Id
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
}
}
# Display the detailed user information
$userDetails | Select-Object Id, DisplayName, UserPrincipalName
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex