问题描述
我想获取特定资源和特定策略的 Azure 策略合规性报告。如何使用 PowerShell 实现这一目标? 例如用于 Azure VM 和自定义策略“拒绝防火墙”。
解决方法
如果想通过PowerShell获取Azure Policy Compliance数据,请参考以下脚本
- 获取特定政策的数据
# get the policy compliance status
Get-AzPolicyState -PolicyDefinitionName <the policy definitionName>
# get the policy evaluation result
Get-AzPolicyEvent -PolicyDefinitionName <the policy definitionName>
2.1.获取特定资源的数据
# get the policy compliance status
Get-AzPolicyState -ResourceId <>
# get the policy evaluation result
Get-AzPolicyEvent -ResourceId <>
更多详情请参考here