Service principals represent applications and services registered in Microsoft Entra ID (Azure AD). As tenants grow, administrators often need a quick, reliable way to know how many service principals exist—either overall or based on specific criteria.
The Get-MgServicePrincipalCount cmdlet provides exactly that by returning a count instead of a full object list, making it fast and efficient for reporting and audits.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Get-MgServicePrincipalCount [-ConsistencyLevel <String> ] [-Filter <String>]
Key parameters:
Get-MgServicePrincipalCount
Returns the total number of service principals in the tenant.
Get-MgServicePrincipalCount -ConsistencyLevel eventual
Explicitly setting the consistency level to eventual
Get-MgServicePrincipalCount -ConsistencyLevel eventual ` -Filter "servicePrincipalType eq 'Application'"
Returns the count of service principals where the type is Application (for example, app registrations and enterprise apps backed by applications).
| Error | Cause | Solution |
|---|---|---|
| Request_UnsupportedQuery | Missing consistency level | Re-run the command with -ConsistencyLevel eventual. |
| Authorization_RequestDenied | Insufficient permissions | Ensure you have Application.Read.All or equivalent admin consent. |
| Count returns 0 unexpectedly | Filter is too restrictive | Review and validate the filter syntax and property names. |
| Cmdlet not recognized | Microsoft.Graph module missing | Install or update the module using Install-Module Microsoft.Graph. |
The Get-MgServicePrincipalCount cmdlet is a simple yet powerful tool for administrators who need quick visibility into service principals without retrieving full object details. By combining it with -ConsistencyLevel eventual and optional filters, you can efficiently support audits, governance, and reporting needs across Microsoft Entra ID.
© m365corner.com. All Rights Reserved. Design by HTML Codex