我对 PowerShell 比较陌生,一直在尝试提取具有特定属性的 Azure 订阅中所有 Key Vault 的列表。这些属性之一是“清除保护已启用”,我已在下面的代码中成功选择了该属性:
$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
}
但是以这种格式提供输出@{EnablePurgeProtection=True}
是否有更好的方法来选择属性或对其进行格式化,使其仅显示“True”或“False”?
谢谢
您的代码可以总结为:
Get-AzKeyVault | Select-Object VaultName, ResourceGroupName, EnablePurgeProtection
无需重新查询每个密钥保管库,您已经在第一次
Get-AzKeyVault
调用中执行此操作。