Answer accepted by question author
Hello Tengku Aiman
Thank you for reaching out to the Microsoft Q&A forum.
When investigated you can absolutely pull policy‐compliance data out of Azure Resource Graph – at least the high-level stuff (which resources are compliant vs. non-compliant, when they were last evaluated, which assignment/definition they belong to, etc.). What you can’t get via Resource Graph is the deep “Compliance details” pane (the per-setting or per-field “Current value” vs. “Target value” info). For that, you’d need to call the Policy Insights APIs (or use az policy state list / PowerShell) instead.
Here’s a quick sample ARG query to list all non-compliant resources for a given assignment:
// Replace with your real assignment ID:
let assignmentId = '/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/InheritTagRG';
policyresources
| where properties.policyAssignmentId == assignmentId
and properties.complianceState == 'NonCompliant'
| extend
resourceId = properties.resourceId,
resourceType = tostring(split(properties.resourceId, '/')[6])
+ '/' + tostring(split(properties.resourceId, '/')[7]),
location = properties.resourceLocation,
lastEvaluated = properties.timestamp
| project resourceId, resourceType, location, lastEvaluated
If you need the extra “Compliance reason” details (fields, current value, target value), switch over to the Policy Insights REST API or CLI:
az policy state list \
--assignment '/subscriptions/…/providers/Microsoft.Authorization/policyAssignments/InheritTagRG' \
--filter "complianceState eq 'NonCompliant'" \
--query "[].{resource:resourceId, reason:complianceReason, details:policyDefinitionAction}" \
--output table
Let me know if any further queries - feel free to reach out!
References
Get compliance data in Portal & ARG samples: https://learn.microsoft.com/azure/governance/policy/how-to/get-compliance-data
Export compliance with Azure Resource Graph: https://learn.microsoft.com/azure/governance/policy/samples/resource-graph-samples
Policy Insights REST API (detailed compliance): https://learn.microsoft.com/azure/governance/policy/concepts/policy-insights-rest-api
az policy state list docs: https://learn.microsoft.com/cli/azure/policy/state#az-policy-state-list
-
Tengku Aiman 120 Reputation points
Alright thank youu. Will try it
-
Siva shunmugam Nadessin 10,895 Reputation points • Microsoft External Staff • Moderator
Tengku Aiman, If the assistance was helpful, kindly 👁 User's image
this can be beneficial to other community members. -
Tengku Aiman 120 Reputation points
Hello sir, this policy is being placed in Management Group scope, do I need to change from subscriptions to scope?
-
Siva shunmugam Nadessin 10,895 Reputation points • Microsoft External Staff • Moderator
Hello Tengku Aiman,
Since the policy is assigned at the Management Group level, you don’t need to change the query logic itself. Azure Resource Graph already evaluates resources across all subscriptions under that management group.
However, you must update the policyAssignmentId to use the Management Group–scoped format, for example:
/providers/Microsoft.Management/managementGroups/{mgId}/providers/Microsoft.Authorization/policyAssignments/{assignmentName}Once the correct assignment ID is used, the query will return results across the inherited scope.
-
Tengku Aiman 120 Reputation points
Using ARG, I can see the results, but the cmd, it returns empty sir
Sign in to comment
