An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
Azure Resource Graph (via CLI)
Bash
az graph query -q "
Resources
| where type == 'microsoft.policyinsights/policystates/latest'
| where properties.policyAssignmentId == '/subscriptions/<your-sub>/resourceGroups/<your-rg>/providers/Microsoft.Authorization/policyAssignments/<your-assignment>'
| mv-expand detail = properties.evaluationDetails.details
| project resourceId = tostring(properties.resourceId),
complianceState = tostring(properties.complianceState),
field = tostring(detail.details.field),
currentValue = tostring(detail.details.currentValue),
targetValue = tostring(detail.details.targetValue)"
This will return one row per non-compliant detail, showing the field, current value, and target value
PowerShell (requires Az.PolicyInsights)
Get-AzPolicyState -Recurse `
-PolicyAssignmentId '/subscriptions/<your-sub>/resourceGroups/<your-rg>/providers/Microsoft.Authorization/policyAssignments/<your-assignment>' `
-ExpandPolicyDetails |
Select-Object ResourceId, ComplianceState, Timestamp,
@{Name= 'Details'; Expression={ $_.PolicyDetails.evaluationDetails.details }} |
Expand-Property Details |
Select-Object ResourceId,
@{Name= 'Field'; Expression={ $_.details.field }},
@{Name= 'CurrentValue'; Expression={ $_.details.currentValue }},
@{Name= 'TargetValue'; Expression={ $_.details.targetValue }}
This expands the evaluation details so you can see exactly why a resource is non-compliant