In Microsoft Entra ID, groups can contain other groups as members, enabling nested group designs for access management and delegation. While listing those nested groups is useful, many scenarios only require a quick count—for example, during audits, governance checks, or reporting.
The Get-MgGroupMemberCountAsGroup cmdlet returns the count of direct group members within a specified group. It excludes users, devices, service principals, and contacts, focusing only on group objects.
Note: This cmdlet requires the -ConsistencyLevel Eventual header to execute successfully.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Get-MgGroupMemberCountAsGroup -GroupId <String>-ConsistencyLevel <String>
Key parameter:
Get-MgGroupMemberCountAsGroup
Explanation:
When run without parameters, the console prompts you to enter the GroupId. After providing it (and setting the required consistency level when prompted), the cmdlet returns the count of direct group members within the specified group.
Get-MgGroupMemberCountAsGroup ` -GroupID 32514d7c-9f70-4fff-9bb4-19b3ab059547 ` -ConsistencyLevel Eventual
Explanation:
Returns the number of direct group members in the specified group, explicitly setting the required ConsistencyLevel header.
Get-MgGroupMemberCountAsGroup | Export-CSV "d:/groupmembercountwithingroup.csv"
Explanation:
Exports the group-member count result to a CSV file. This is useful when collecting counts across multiple groups for audit or reporting purposes.
| Error / Message | Cause | Solution |
| Request_UnsupportedQuery | Missing consistency level | Re-run the cmdlet with -ConsistencyLevel Eventual. |
| Authorization_RequestDenied | Insufficient permissions | Ensure Group.Read.All permission is granted with admin consent. |
| Count returns 0 unexpectedly | No direct group members | Verify whether the group actually contains nested group members. |
| ResourceNotFound | Invalid GroupId | Confirm the group object ID in the Entra admin center. |
| Cmdlet not recognized | Microsoft.Graph module missing | Install or update using Install-Module Microsoft.Graph. |
The Get-MgGroupMemberCountAsGroup cmdlet provides a fast and reliable way to determine how many groups are nested within another group in Microsoft Entra ID. By requiring the -ConsistencyLevel Eventual header and returning a simple count, it delivers efficient, user-friendly reporting for audits, governance, and access management scenarios without unnecessary overhead.
© m365corner.com. All Rights Reserved. Design by HTML Codex