Service principals represent applications, services, or automation tools in Microsoft Entra ID. They're essential for managing app identities and permissions within your tenant. IT admins use service principals to configure SSO, grant API permissions, and control access to resources. The Get-MgServicePrincipal command in Microsoft Graph PowerShell helps list and inspect these identities, but it requires familiarity with scripting and interpreting raw property data.
Before running the cmdlet, ensure the following requirements are met:
If not already installed, run:
Install-Module Microsoft.Graph -Scope CurrentUser
You'll need directory read access. Connect using:
Connect-MgGraph -Scopes "Directory.Read.All"
Use the Get-MgServicePrincipal cmdlet in Microsoft Graph PowerShell to get service principals in Entra ID. The syntax is as follows:
Get-MgServicePrincipal
[-Property <String[]>]
[-ExpandProperty <String[]>]
[-Filter <String>]
[-Search <String>]
[-Skip <Int32>]
[-Sort <String[]>]
[-Top <Int32>]
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-PageSize <Int32>]
[-All]
[-CountVariable <String>]
[<CommonParameters>]
Get-MgServicePrincipal -Filter "DisplayName eq 'Microsoft Teams'" |
Format-List Id, DisplayName, AppId, SignInAudience
The table below lists key parameters that can be used with the Get-MgServicePrincipal cmdlet to get service principals in Entra ID.
| Parameters | Description |
|---|---|
| -Property | Specifies which properties to return in the response. |
| -ExpandProperty | Expands related entities inline (like owners or appRoleAssignments). |
| -Filter | Filters the results based on property values (OData filter syntax). |
| -Search | Searches across indexed properties. |
| -Skip | Skips a specified number of results. |
| -Sort | Sorts the results by one or more properties. |
| -Top | Limits the number of results returned. |
| -ResponseHeadersVariable | Stores response headers in a variable. |