I'm relatively new to PowerShell and have been trying to pull a list of all the Key Vaults in our Azure subscription with specific properties. One of these properties is Purge Protection Enabled, which I've managed to select in the code below:
$kvs = Get-AzKeyVault
foreach ($kv in $kvs) {
$resourceDetail = [PSCustomObject]@{
KVName = $kv.VaultName
ResourceGroup = $kv.ResourceGroupName
PurgeProtection = Get-AzKeyVault -VaultName $kv.VaultName | Select-Object -Property EnablePurgeProtection
}
$resourceDetail
}
However the output is provided in this format @{EnablePurgeProtection=True}
Is there a better way of selecting the property or formatting it so that it just shows "True" or "False?
Thanks
Your code can be summarized to:
There is no need to re-query each key vault, you're already doing that on your first
Get-AzKeyVaultcall.If you want custom names for your properties you can use calculated properties, though code becomes less readable.
Another way to do it using
Search-AzGraph: