Get-MgGroupMemberCountAsGroup: Graph PowerShell Cmdlet

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.

🚀 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.

i) Cmdlet Syntax

Get-MgGroupMemberCountAsGroup  -GroupId  <String>-ConsistencyLevel <String>

Key parameter:

  • -GroupId: The object ID of the Microsoft 365 or Entra ID group whose group-member count you want to retrieve.
  • -ConsistencyLevel: Must be set to Eventual. This parameter is mandatory for the cmdlet to run.

ii) Usage Examples

Example 1: Passing GroupId when requested by the console

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.


Example 2: Passing GroupId directly with ConsistencyLevel

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.


Example 3: Exporting the results to CSV

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.


iii) Cmdlet Tips

  • -ConsistencyLevel Eventual is mandatory; the cmdlet will fail without it.
  • The cmdlet returns only a numeric count, not group objects.
  • Counts direct group members only; nested groups within nested groups are not expanded.
  • Non-group objects (users, devices, service principals, contacts) are automatically excluded.
  • Useful for lightweight reporting where performance is more important than detailed output.

iv) Possible Errors & Solutions

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.

v) Conclusion

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.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

© m365corner.com. All Rights Reserved. Design by HTML Codex