How to Use Get-MgUserCount to Fetch Microsoft 365 User Count?

Keeping track of user accounts in your Microsoft 365 environment is essential for effective licensing, compliance, and security management. Whether you're monitoring active users or checking for deprovisioned accounts, the Get-MgUserCount cmdlet makes it simple to fetch user counts directly via Microsoft Graph PowerShell.

In this guide, we’ll walk you through everything you need to know to get started with Get-MgUserCount.

What is Get-MgUserCount?

Get-MgUserCount is a Microsoft Graph PowerShell cmdlet used to retrieve the total number of user accounts in your Microsoft 365 tenant. It supports filtering with OData syntax to return counts for specific subsets of users, such as enabled, disabled, guest, or licensed accounts.

Unlike Get-MgUser -All, which retrieves full user objects, Get-MgUserCount simply returns a count—making it faster and more efficient for reporting.

Why Use Get-MgUserCount?

Here’s why Get-MgUserCount is a must-have in your admin toolkit:

  • Quick Insights: Instantly know how many users exist in your environment.
  • License Planning: See how many users are active vs. inactive for better license allocation.
  • Security Audits: Identify disabled accounts that may need cleanup.
  • Reporting Automation:: Integrate user count tracking into your scripts or dashboard reports.

Cmdlet Syntax

Get-MgUserCount [-ConsistencyLevel <String>] [<CommonParameters>]

Key Parameter:

  • -ConsistencyLevel: Use eventual to enable advanced queries such as filtering and to improve query scalability. Required when using -Filter.

Usage Examples

Example 1: Get the Total User Count in Microsoft 365

Get-MgUserCount -ConsistencyLevel eventual

This returns the total number of users in your Microsoft 365 tenant, including guests and service accounts.

Example 2: Get the Count of Disabled Accounts

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

This filters out all user accounts where accountEnabled is false—essential for identifying deactivated or suspended accounts.

Example 3: Get the Count of Enabled Accounts

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

Use this to count only active users, which is helpful for monitoring license consumption or user activity.

Frequently Asked Questions

  • Do I need special permissions to run Get-MgUserCount?
  • Yes, you’ll need at least User.Read.All or Directory.Read.All delegated permissions. For app-based access, ensure that your registered app has Directory.Read.All application permissions with admin consent.

  • Why is -ConsistencyLevel eventual required for filtering?
  • The -ConsistencyLevel eventual parameter enables support for advanced OData queries (like -Filter) and ensures accurate results when filtering large datasets in Microsoft Graph.

  • Does Get-MgUserCount include guest users?
  • Yes, by default Get-MgUserCount includes all user types—members, guests, and service accounts—unless you apply a filter like:

    -Filter "userType eq 'Member'"
  • Can I export the count to a file?
  • Yes! You can redirect the output to a text file using:

    (Get-MgUserCount).Value | Out-File "UserCount.txt"

    This is useful for automating reports or logging.

Use Cases

  • Auditing: Track enabled/disabled users for compliance reviews.
  • License Management: Get accurate user counts to optimize license purchases.
  • Periodic Reports: Automate user counts for monthly dashboards.
  • Clean-up: Identify dormant or disabled accounts for review or deletion.

Conclusion

The Get-MgUserCount cmdlet is a simple yet powerful way to gain visibility into your Microsoft 365 user landscape. Whether you're an IT admin, security analyst, or PowerShell enthusiast, this cmdlet helps you stay informed and in control with minimal overhead.

📌 Tip: Combine it with filters and consistency level for targeted reporting that scales with your organization.

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