Get-MgUserCount

What is Get-MgUserCount?

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.


Why Use Get-MgUserCount?

This cmdlet is extremely useful for user management and reporting in Microsoft 365. Administrators use it to:

  • Get a quick overview of total users in the tenant.
  • Count active vs. disabled accounts.
  • Automate compliance, audit, or license management scripts.
  • Integrate user count data into usage reports and dashboards.

It helps reduce the overhead of retrieving entire user objects, saving time and resources in automation workflows.


Prerequisites

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"

How to Use Get-MgUserCount?

Use the -ConsistencyLevel parameter for accurate results across large datasets. The Eventual consistency level ensures complete data aggregation.

Get-MgUserCount -ConsistencyLevel  <String>

Get-MgUserCount Examples

Example 1: Get the Total User Count in Microsoft 365

This command retrieves the total number of users in the tenant.

Get-MgUserCount -ConsistencyLevel Eventual

Example 2: Get the Count of Disabled Accounts

This command retrieves the count of all disabled user accounts in the organization.

Get-MgUserCount -ConsistencyLevel Eventual -Filter "accountEnabled eq false"

Example 3: Get the Count of Enabled or Active Accounts

This command retrieves the count of all enabled user accounts in the tenant.

Get-MgUserCount -ConsistencyLevel Eventual -Filter "accountEnabled eq true"

Summary

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