Service principals are at the heart of how apps authenticate and access resources in Microsoft Entra ID (Azure AD). If you manage Microsoft 365 or Entra, you’ll bump into them constantly—Enterprise Applications, managed identities, app registrations that have been consented in your tenant… all of those show up as service principals. This guide walks you through the Get-MgServicePrincipal cmdlet in Microsoft Graph PowerShell with practical, admin-friendly examples.
Get-MgServicePrincipal is a Microsoft Graph PowerShell cmdlet from the Microsoft.Graph.Applications module. It retrieves properties and relationships of servicePrincipal objects from your tenant. In Entra terms, a service principal is the “tenant-local” representation of an application (either Microsoft, third-party SaaS, or your own app registration).
The cmdlet supports:
Here’s why admins rely on this cmdlet:
Install-Module Microsoft.Graph.Applications -Scope CurrentUser
Import-Module Microsoft.Graph.Applications
You need appropriate permissions. For read-only operations, Application.Read.All is typically enough.
Connect-MgGraph -Scopes "Application.Read.All"
List all
Get-MgServicePrincipal
Get by ID
Get-MgServicePrincipal -ServicePrincipalId <ServicePrincipalId>
List with query options
Get-MgServicePrincipal -Filter <ODataFilter> -Top <n> -Property <props>
The cmdlet supports standard OData parameters like -Filter, -Search, -Top, -Sort, -Skip, -All, -Property, and -ExpandProperty.
Important: Some queries (like -Search or advanced $filter + count) require -ConsistencyLevel eventual and -CountVariable.
Below are the same practical examples you asked for, with a bit of context.
Get-MgServicePrincipal
This returns every service principal in the directory (paged). Use -All if you want everything without manual paging.
Get-MgServicePrincipal -ServicePrincipalId 015993cd-d59a-4f62-a76b-72fa58ed36e3
Use this when you already know the object ID (ServicePrincipalId) from Entra or logs.
Get-MgServicePrincipal -Filter "DisplayName eq 'Power BI Service'" | Format-List Id, DisplayName, AppId, SignInAudience
This is the cleanest way to find one known app by name. -Filter uses OData syntax.
Get-MgServicePrincipal -ConsistencyLevel eventual -Count spCount -Filter "startsWith(DisplayName, 'a')" -Top 5
startsWith() is an advanced query, so you must include:
Get-MgServicePrincipal -ConsistencyLevel eventual -Count spCount -Search '"DisplayName:Team"'
Notes:
Here are the field-tested tips I’d recommend for M365Corner readers:
For read-only reporting:
Connect-MgGraph -Scopes "Application.Read.All"
Only elevate to write permissions (like Application.ReadWrite.All) when needed.
Instead of pulling everything:
Get-MgServicePrincipal -All
Limit properties:
Get-MgServicePrincipal -All -Property Id,DisplayName,AppId,PublisherName
This reduces payload, speeds execution, and is friendlier for exports.
By default, Graph returns paged results. If your goal is a full report, use:
Get-MgServicePrincipal -All
If you see errors like “Request_UnsupportedQuery” or missing results for advanced queries, add:
-ConsistencyLevel eventual -CountVariable spCount
This applies to many directory object advanced queries.
Display names can change. If you want a stable lookup, use:
Example:
Get-MgServicePrincipalByAppId -AppId "60dbf324-9702-41cc-a5fa-f8d19804b014"
Typical export pattern:
Get-MgServicePrincipal -All -Property Id,DisplayName,AppId,PublisherName,AccountEnabled | Select-Object Id,DisplayName,AppId,PublisherName,AccountEnabled | Export-Csv "ServicePrincipals.csv" -NoTypeInformation
Get-MgServicePrincipal is a must-know cmdlet for any Microsoft 365 or Entra admin. Whether you’re auditing Enterprise Applications, troubleshooting SSO, reviewing risky apps, or building tenant-wide app inventories, this cmdlet gives you the core dataset to start from.
Use -Filter, -Search, and -Top for targeted queries, and remember the advanced query rule: ConsistencyLevel eventual + CountVariable whenever you’re doing search or complex filters. With these patterns, you can turn service principal management into clean, repeatable automation.
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