The Get-MgGroupMember cmdlet is part of the Microsoft Graph PowerShell module, which enables administrators to manage Microsoft 365 resources efficiently. This cmdlet is specifically designed to retrieve the members of a given Microsoft 365 group, making it an essential tool for user and group management.
Administrators often need to check which users belong to a particular group to manage permissions, audit group memberships, or ensure compliance with company policies. The Get-MgGroupMember cmdlet simplifies this process by allowing admins to fetch group members quickly and, when necessary, retrieve additional details about each user.
Get-MgGroupMember -GroupId <GroupId> [-All] [-Filter <String>] [-Search <String>]
Key Parameters:
Get-MgGroupMember -GroupId "1cbe8c31-589d-453a-a1e5-045f7f00c967"
This command retrieves all members of the specified group.
Get-MgGroupMember
If no -GroupId parameter is provided, the console may prompt the user to enter a valid group ID interactively.
The following script retrieves detailed user information for each group member:
# 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
This script enhances the basic Get-MgGroupMember output by pulling additional user properties using the Get-MgUser cmdlet.
No, Get-MgGroupMember works on a single group at a time. You would need to loop through multiple group IDs.
It returns all members, including users, service principals, and devices if they are part of the group.
Use the Get-MgGroupMember cmdlet and filter the output based on the user ID.
@odata.type
in Post-Retrieval FilteringGet-MgGroupMember
cmdlet returns a mix of directory objects—including users, guests, service principals, devices, or nested groups.
After retrieving the members, inspect the @odata.type
property to accurately distinguish guest users (e.g., objects with @odata.type
equal to #microsoft.graph.user
and a userType
of Guest
).
-All
or Handle Paging for Complete ResultsGet-MgGroupMember
returns a limited number of items per call.
To retrieve all members—especially in large groups—use the -All
parameter or handle @odata.nextLink
pagination in a loop to avoid missing entries.
The Get-MgGroupMember cmdlet is a powerful tool for Microsoft 365 administrators, allowing them to quickly fetch group members and retrieve additional user details when necessary. Whether used for audits, automation, or troubleshooting, this cmdlet simplifies group membership management and enhances administrative efficiency. By leveraging it effectively, admins can ensure a well-maintained and organized Microsoft 365 environment.
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