0

I am trying to get reports for expiry date of Azure AD SPN credentials using Az cli.

I am able to get reports using Az cli "az ad sp credential list" but stuck with date conversion.


az ad sp credential list --id xxxxxx-xxx-xxx-xx  --query '[].{Key:customKeyIdentifier,expirydate:endDate}' -o table

output:

Expirydate                        Key
--------------------------------  ---------------
2299-12-30T23:00:00+00:00         Test
2020-01-10T13:13:12.647000+00:00  Qa
2299-12-30T16:00:00+00:00         Dev

is there a way to convert the expiry date output to standard date

i.e 2299-12-30T23:00:00+00:00 -> 30-12-2299

Any suggestion? Thanks in advance.

paulpuvi
  • 45
  • 1
  • 1
  • 7

1 Answers1

0

I wasn't able to find a way to do it with the az cli itself, but here is a solution using jq

az ad sp credential list --id <sub-id> | jq -r \ '["Expiry Date", "Key"], ["-----------", "---"], (.[] | [(.endDate | (sub("\\.[0-9]+\\+"; "+") | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime | strftime("%d-%m-%Y"))), .customKeyIdentifier // "-"]) | @tsv'

And the extended version to see what's going on

az ad sp credential list --id <sub-id> | jq -r \
'
["Expiry Date", "Key"],
["-----------", "---"],
(.[] | [
  (
    .endDate | 
    (
      sub("\\.[0-9]+\\+"; "+") | 
      strptime("%Y-%m-%dT%H:%M:%S%z") | 
      mktime | 
      strftime("%d-%m-%Y")
    )
  ),
  .customKeyIdentifier // "-"
]) |
@tsv
'
PramodValavala
  • 6,026
  • 1
  • 11
  • 30
  • thanks , it did not work for dates with following format 2020-01-10T13:13:12.647000+00:00 . Hence, i mixed up az cli and powershell to get the desired output. – paulpuvi Aug 15 '19 at 13:33