gpt4 book ai didi

azure - Powershell 中的 Get-AzPolicyState 与 az cli 形式的 az 策略状态列表之间的差异

转载 作者:行者123 更新时间:2023-12-03 07:03:06 28 4
gpt4 key购买 nike

如果我运行命令

Get-AzPolicyState -PolicyAssignmentName "xxxxxxxxxxxxxxxxxxxxx" -Filter "ResourceType eq 'Microsoft.KeyVault/vaults'" # | where-object { $_.ComplianceState -eq "NonCompliant" }

我收到一个示例响应:

Timestamp                   : 22/04/2022 11:38:58
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/group_name/providers/microsoft.keyvault/vaults/resouce_name
PolicyAssignmentId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.authorization/policyassignments/xxxxxxxxxxxxxxxxxx
PolicyDefinitionId : /providers/microsoft.authorization/policydefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
IsCompliant : False
SubscriptionId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ResourceType : Microsoft.KeyVault/vaults
ResourceLocation : northeurope
ResourceGroup : neu-rg-dev-bicep
ResourceTags : tbd
PolicyAssignmentName : xxxxxxxxxxxxxxxxxxxxxx
PolicyAssignmentOwner : tbd
PolicyAssignmentScope : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PolicyDefinitionName : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PolicyDefinitionAction : audit
PolicyDefinitionCategory : tbd
PolicySetDefinitionId : /providers/Microsoft.Authorization/policySetDefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PolicySetDefinitionName : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PolicySetDefinitionCategory : security center
ManagementGroupIds : MSDN,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
PolicyDefinitionReferenceId : keyvaultsshouldhavepurgeprotectionenabledmonitoringeffect
ComplianceState : NonCompliant
AdditionalProperties : {[complianceReasonCode, ]}

与Az cli对应的命令是

az policy state list --filter "ResourceType eq 'Microsoft.KeyVault/vaults'" --query "[?complianceState=='NonCompliant']"

结果:

  {
"complianceReasonCode": "",
"complianceState": "NonCompliant",
"components": null,
"effectiveParameters": "",
"isCompliant": false,
"managementGroupIds": "MSDN,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"odataContext": "https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
"odataId": null,
"policyAssignmentId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/microsoft.authorization/policyassignments/xxxxxxxxxxxxxxxxxx",
"policyAssignmentName": "a26a6876d6c14a45b79d547f",
"policyAssignmentOwner": "tbd",
"policyAssignmentParameters": "",
"policyAssignmentScope": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"policyAssignmentVersion": "",
"policyDefinitionAction": "audit",
"policyDefinitionCategory": "tbd",
"policyDefinitionGroupNames": [
"azure_security_benchmark_v3.0_dp-8"
],
"policyDefinitionId": "/providers/microsoft.authorization/policydefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"policyDefinitionName": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"policyDefinitionReferenceId": "keyvaultsshouldhavepurgeprotectionenabledmonitoringeffect",
"policyDefinitionVersion": "2.0.0",
"policyEvaluationDetails": null,
"policySetDefinitionCategory": "security center",
"policySetDefinitionId": "/providers/Microsoft.Authorization/policySetDefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"policySetDefinitionName": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"policySetDefinitionOwner": "",
"policySetDefinitionParameters": "",
"policySetDefinitionVersion": "47.0.0",
"resourceGroup": "group_name",
"resourceId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/group_name/providers/microsoft.keyvault/vaults/resource_name",
"resourceLocation": "northeurope",
"resourceTags": "tbd",
"resourceType": "Microsoft.KeyVault/vaults",
"subscriptionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"timestamp": "2022-04-22T11:38:58.831865+00:00"
}

正如我们所见,有一些信息与 powershell 版本无关。 policyDefinitionGroupNames 是具有重大影响的属性之一。

有人知道如何使用 powershell 获取该属性吗?

最佳答案

Does anyone know a way to get that property using powershell

正如上面@Todd所建议的,我们已经尝试了同样的方法来获得您正在寻找的特性,

尝试使用以下cmdlts:

$outVar = Get-AzPolicyState -PolicyAssignmentName "xxxxxxxxx0" -Filter "ResourceType eq 'Microsoft.KeyVault/vaults'" # | where-object { $_.ComplianceState -eq "NonCompliant" }

enter image description here

要检查该属性是否可用,请使用 $outVar |获取成员(member)

enter image description here

欲了解更多信息,请参阅此MS DOC| Get-AzPolicyState & Azure policy Definition structure

关于azure - Powershell 中的 Get-AzPolicyState 与 az cli 形式的 az 策略状态列表之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71970437/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com