Last active
January 26, 2021 18:56
-
-
Save heaths/a995efefd23a188619e802b505fce763 to your computer and use it in GitHub Desktop.
Gets a list of Key Vaults from the currently selected subscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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