Skip to content

Instantly share code, notes, and snippets.

@heaths
Last active January 26, 2021 18:56
Show Gist options
  • Save heaths/a995efefd23a188619e802b505fce763 to your computer and use it in GitHub Desktop.
Save heaths/a995efefd23a188619e802b505fce763 to your computer and use it in GitHub Desktop.
Gets a list of Key Vaults from the currently selected subscription
$vaults = az resource list --resource-type Microsoft.KeyVault/vaults | convertfrom-json
$managedHsms = az resource list --resource-type Microsoft.KeyVault/managedHSMs | convertfrom-json
$lookup = $vaults + $managedHsms | group id -asstring -ashashtable
function get-delta ($dt) {
if ($dt -ge [datetime]::now.adddays(-1)) {
'<= 1d'
} elseif ($dt -ge [datetime]::now.adddays(-7)) {
'<= 7d'
} elseif ($dt -ge [datetime]::now.adddays(-30)) {
'<= 30d'
} elseif ($dt -ge [datetime]::now.adddays(-90)) {
'<= 90d'
} else {
'> 90d'
}
}
az keyvault list --query '[].{name: name, id: id, sku: sku.name, type: type}' | convertfrom-json | foreach {
$created = get-delta $lookup[$_.id].createdTime
$changed = get-delta $lookup[$_.id].changedTime
$_ | add-member -name created -type noteproperty -value $created -passthru `
| add-member -name changed -type noteproperty -value $changed -passthru
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment