azurepowershellcommand-line-interface

How do I get a list of Service Principals in Azure via the CLI


When I run az ad sp list, I get a list of service principals which includes an accountEnabled attribute:

enter image description here

I adjusted the command to show only the ones that are enabled using this command:

az ad sp list | where-object { $_.AccountEnabled -eq 'true' }

However, when I do, I get no results. What's the correct method for listing the active Service Principals?


Solution

  • To list the service principal based on accountEnabled = true using Azure CLI

    When I ran, the command mentioned by you, I got following response:

    az ad sp list | where-object { $_.AccountEnabled -eq 'true' }
    

    Response:

    enter image description here

    To resolve the error use this modified command:

    az ad sp list --filter "accountEnabled eq true" --output json
    

    Response:

    enter image description here

    To list the service principal with accountEnabled = true using PowerShell, use this:

    Get-AzADServicePrincipal 
        | Where-Object { $_.AccountEnabled -eq $true } 
        | Select-Object DisplayName, AppId, AccountEnabled
    

    Response:

    enter image description here

    References: