PowerShell Genie

Inventory service principals

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

List tenant service principals with Microsoft Graph PowerShell. Review application identities and the properties returned by the inventory.

The script

1PS> Get-MgServicePrincipal -All -Property DisplayName,AppId,AccountEnabled,ServicePrincipalType | Select-Object DisplayName,AppId,AccountEnabled,ServicePrincipalType

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 DisplayName AppId AccountEnabled ServicePrincipalType
    2 ----------- ----- -------------- --------------------
    3 Sample object 11111111-2222-3333-4444-555555555555 True Application
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-MgServicePrincipal -All -Property DisplayName,AppId,AccountEnabled,ServicePrincipalType | Select-Object DisplayName,AppId,AccountEnabled,ServicePrincipalType
    1. Stage 1Get-MgServicePrincipal-All -Property
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      List tenant service principals with Microsoft Graph PowerShell. Review application identities and the properties returned by the inventory. The projection keeps the display name with the AppId that identifies the underlying application, AccountEnabled, and ServicePrincipalType, which is what separates an application principal from a managed identity.

      Adapting it

      Filter on ServicePrincipalType eq 'ManagedIdentity' to review only identities attached to Azure resources, since those and third-party applications raise entirely different questions.

      Requirements

      Microsoft.Graph module and a Graph session with Application.Read.All.

      If the result is unexpected

      A service-principal report is confused with the app-registration inventory.

      Service principals are tenant instances of applications and are distinct from application objects.

      1. Compare the service principal object ID and AppId with the relevant application record.

      Validate the result

      The report labels object IDs and application IDs correctly and includes the intended enterprise application.

      Keep the check reliable

      Keep application objects and service principals in separate inventory columns or datasets.

      Primary documentation

      Windows services and processes documentation

      Continue
      Genie guideInventory service principals

      List tenant service principals with Microsoft Graph PowerShell. Review application identities and the properties returned by the inventory.