Who Are Microsoft 365 Group Members?
Microsoft 365 groups enable seamless collaboration by connecting a group of users to shared tools like Outlook, Teams, SharePoint, and Planner. Each member of a group is an account (user or service principal) that has specific permissions and access to resources.
Admins manage group memberships to:
- Ensure proper access control.
- Facilitate effective communication within teams.
- Maintain up-to-date membership records for security and compliance
Why Use Get-MgGroupMember?
The Get-MgGroupMember cmdlet provides a programmatic way to fetch the members of any Microsoft 365 group. While the Admin Center allows manual membership management, Get-MgGroupMember shines in scenarios requiring:
- Bulk queries for multiple groups.
- Automation of membership monitoring tasks.
- Detailed reporting on group memberships.
Setting Up Microsoft Graph PowerShell
To use the Get-MgGroupMember cmdlet, you need to set up the Microsoft Graph PowerShell module. Here’s how:
1. Install the Module
Run this command in PowerShell to install the module:
Install-Module Microsoft.Graph -Scope CurrentUser
2. Connect to Microsoft Graph
Once installed, connect to your Microsoft 365 tenant:
Connect-MgGraph
3. Disconnect After Use
When finished, disconnect to secure your session:
Disconnect-MgGraph
Exploring the Get-MgGroupMember Cmdlet
The Get-MgGroupMember cmdlet retrieves members of a specified Microsoft 365 group. Whether you want a quick list of user IDs or detailed user information, this cmdlet offers flexibility and power.
Cmdlet Syntax
Get-MgGroupMember [-GroupId <String>] [-Filter <String>] [-All <Boolean>] [<CommonParameters>]
Key Parameters & Query Options (Quick Reference)
Understanding the available parameters helps administrators retrieve membership data efficiently.
| Parameter | Purpose |
| GroupId | Retrieve members of a specific group |
| All | Retrieve all members (handles pagination) |
| Top | Limit number of returned results |
| Filter | Filter membership results |
| Search | Search for members |
| Property | Retrieve specific properties |
| ExpandProperty | Expand related objects |
Usage Examples
- Passing Group ID Directly
- Passing Group ID When Prompted by Console
- Get-MgGroupMember Returns Only Member or User IDs by Default
- Use Get-MgUser with Get-MgGroupMember to Get Detailed User Information
To fetch members of a specific group by its unique ID:
Get-MgGroupMember -GroupId "1cbe8c31-589d-453a-a1e5-045f7f00c967"
This command returns the IDs of all group members.
If you directly execute the Get-MgGroupMember cmdlet without the group id, the console prompts you to enter the same.
Get-MgGroupMember
Note: You can get the group id by executing Get-MgGroup cmdlet.
The output of Get-MgGroupMember includes only the IDs of group members, not personal details like names or email addresses. While this information is sufficient for some use cases, administrators often require additional user details.
Get-MgUser -UserId "john.doe@contoso.com"
To fetch additional information like DisplayName, UPN, or Mail, combine Get-MgGroupMember with Get-MgUser:
# 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 retrieves and displays user details for all group members, providing the information needed for advanced reporting or management tasks.
When Should You Use Get-MgGroupMember?
Use the Get-MgGroupMember cmdlet in the following scenarios:
- Auditing Microsoft 365 group memberships
- Generating access review reports
- Tracking security group members
- Validating onboarding/offboarding processes
- Building governance and compliance reportss
Get-MgGroupMember vs Related Cmdlets
| Cmdlet | Purpose | When to Use |
| Get-MgGroupMember | Retrieve group members | Auditing & reporting |
| New-MgGroupMember | Add members | Provisioning |
| Remove-MgGroupMember | Remove members | Access cleanup |
| Get-MgGroup | Retrieve group details | Metadata & configuration |
Real-World Admin Scenarios
- Membership Audit & Compliance Reporting
- Retrieve all members of sensitive groups
- Validate access permissions for compliance audits
- Offboarding Validation
- Ensure departed employees are removed from all groups
- Prevent unauthorized access retention
- Tenant-Wide Membership Reporting
- Combine Get-MgGroup with Get-MgGroupMember
- Generate organization-wide membership inventories
- Teams Membership Validation
- Since Teams are backed by Microsoft 365 Groups, this cmdlet can help validate Team membership indirectly
Common Limitations & Considerations
Strengths
- Supports detailed membership auditing
- Works with Microsoft 365 and security groups
- Useful for automation and reporting
Limitations
- Requires GroupId for queries
- Large groups may require pagination handling
- Does not always return full user properties directly
Pro Tips for Using Get-MgGroupMember
- Use -All when working with large groups
- Export results to CSV for audits and reporting
- Combine with Get-MgGroup for tenant-wide analysis
- Use Select-Object to retrieve only required properties
- Automate recurring membership reviews
Example: End-to-End Group Membership Reporting Workflow
A practical reporting workflow could look like:
- Retrieve all groups using Get-MgGroup
- Loop through each group
- Retrieve members using Get-MgGroupMember
- Export membership data to CSV
- Analyze data using Excel or Power BI
Best Practices for Get-MgGroupMember
- Limit Scope: Use filters or specific parameters to retrieve only the data you need, avoiding excessive data pulls.
- Combine with Other Cmdlets: Combine Get-MgGroupMember with cmdlets like Get-MgUser or Remove-MgGroupMember to create workflows for automation.
- Simulate Actions: Use the -WhatIf parameter to preview commands and avoid unintended changes.
- Secure Access: Always disconnect from Microsoft Graph after completing tasks to maintain security.
A common “wait…why is my user missing?” moment: this cmdlet lists only direct members. So if a group includes another group, those nested users won’t show up.
You should use Get-MgGroupTransitiveMember cmdlet if you wish to fetch all nested users as well.
Your output isn’t guaranteed to be only users. Microsoft 365 groups (and security groups) can contain:
- Users
- Devices
- Service principals (apps)
- Other groups
Example snippet to illustrate the idea:
$members = Get-MgGroupMember -GroupId $groupId -All
$usersOnly = $members | Where-Object { $_.'@odata.type' -eq '#microsoft.graph.user' }
Frequently Asked Questions
- What is Get-MgGroupMember used for?
Get-MgGroupMember is used to retrieve members of Microsoft 365 groups and security groups using Graph PowerShell. - Can I retrieve all members of a group?
Yes. Using the -All parameter, you can retrieve all members, including large groups. - What permissions are required?
Permissions such as Group.Read.All or GroupMember.Read.All are commonly required. - Can I retrieve members from all groups at once?
Not directly. Typically, administrators use Get-MgGroup to retrieve groups and then loop through them with Get-MgGroupMember. - Does Get-MgGroupMember work for Teams?
Yes. Since Microsoft Teams are backed by Microsoft 365 Groups, the cmdlet can retrieve Team members indirectly.
Conclusion
The Get-MgGroupMember cmdlet is a versatile tool for Microsoft 365 administrators, offering an efficient way to query group memberships. By combining it with other Graph PowerShell cmdlets, admins can unlock advanced capabilities, from fetching detailed user information to automating membership management.
Whether you’re managing a small team or overseeing an enterprise environment, mastering Get-MgGroupMember will save time, reduce errors, and enhance productivity.
🚀 Community Edition Released!
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Get it on GitHub Know More