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.
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.
Here’s why Get-MgUserCount is a must-have in your admin toolkit:
Get-MgUserCount [-ConsistencyLevel <String>] [<CommonParameters>]
Key Parameter:
Get-MgUserCount -ConsistencyLevel eventual
This returns the total number of users in your Microsoft 365 tenant, including guests and service 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.
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.
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.
The -ConsistencyLevel eventual parameter enables support for advanced OData queries (like -Filter) and ensures accurate results when filtering large datasets in Microsoft Graph.
Yes, by default Get-MgUserCount includes all user types—members, guests, and service accounts—unless you apply a filter like:
-Filter "userType eq 'Member'"
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.
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