The Get-MgUserCount cmdlet retrieves the total number of users in a Microsoft 365 tenant. It’s part of the Microsoft Graph PowerShell SDK and is used to quickly return user counts without fetching detailed user information, making it highly efficient for large organizations.
This cmdlet is extremely useful for user management and reporting in Microsoft 365. Administrators use it to:
It helps reduce the overhead of retrieving entire user objects, saving time and resources in automation workflows.
Before using the cmdlet, ensure the Microsoft Graph PowerShell module is installed and you are connected to Microsoft Graph with the appropriate permissions.
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.Read.All"
Use the -ConsistencyLevel parameter for accurate results across large datasets. The Eventual consistency level ensures complete data aggregation.
Get-MgUserCount -ConsistencyLevel <String>
This command retrieves the total number of users in the tenant.
Get-MgUserCount -ConsistencyLevel Eventual
This command retrieves the count of all disabled user accounts in the organization.
Get-MgUserCount -ConsistencyLevel Eventual -Filter "accountEnabled eq false"
This command retrieves the count of all enabled user accounts in the tenant.
Get-MgUserCount -ConsistencyLevel Eventual -Filter "accountEnabled eq true"
| Key Point | Details |
|---|---|
| Cmdlet Name | Get-MgUserCount |
| Purpose | Retrieves the total number of users in a Microsoft 365 tenant |
| Required Scope | User.Read.All |
| Primary Parameter | ConsistencyLevel, Filter |
| Automation Benefit | Enables quick and efficient user count reporting |
| Use Case | Useful for auditing, compliance, and active/disabled user monitoring |
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