Forum Discussion

Brahmaiah's avatar
Brahmaiah
Copper Contributor
Oct 23, 2020
Solved

ServicePrincipal StartDate and EndDate not displaying Using Graph API In Power Shell

Hi,   I am trying to get list of SPNs that are going to expire soon. Using Graph API  I am executing below powershell script.   I am getting output appid and name always but StartDate and EndDate...
  • Command0r's avatar
    Oct 24, 2020

    Brahmaiah, you can use Azure CLI for exact same purpose. Do the following:

    • Sign-in to your account in azure
    • Open up a Cloud shell
    • Once Azure Cloud Shell is initialized in the account, click on curly braces in the panel to open editor (see screenshots attached below)
    • Insert the following command that will extract expiring SPs in the next 60 days (adjust the timeframe if needed):
    az ad sp list \
      --all \
      --query "[?passwordCredentials[0].endDate<='$(date -d "+60 days" +%Y-%m-%d)'||keyCredentials[0].endDate<='$(date -d "+60 days" +%Y-%m-%d)'].{\"App ID Display Name\":appDisplayName,\"SP appId\":appId,\"Password Expiry Date\":passwordCredentials[0].endDate, \"Key Expiry Date\":keyCredentials[0].endDate}" \
      -o table
    • Save this script with whatever filename you want ("sp-list" in my case)
    • Execute with "bash sp-list"
    • Enjoy the list :smile:

     

    Screenshots:

    Edit

    Execute

Resources