Share via

View Compliance Details with Azure Resource Graph or Powershell

Tengku Aiman 0 Reputation points
2026-05-05T06:30:46.82+00:00

Hello, I am trying to view compliance details in View Compliance for Policy compliance builtin "Inherit a tag from the resource group"

Right now I can see from the portal

Reason for non-compliance

Current value must be equal to the target value.

Field

tags[]

Current value

--

Target value

"a"

Reason for non-compliance

Current value must be equal to the target value.

Expression

[resourceGroup().tags[parameters('tagName')]]

Current value

"a"

Target value

""

How can I fetch this using Azure Resource Graph or Powershell?

Azure Policy
Azure Policy

An Azure service that is used to implement corporate governance and standards at scale for Azure resources.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Ntwanano Biggs 0 Reputation points
    2026-05-05T12:41:43.26+00:00

    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

    1 person found this answer helpful.
    0 comments No comments

  2. Siva shunmugam Nadessin 9,625 Reputation points Microsoft External Staff Moderator
    2026-05-05T07:34:53.1566667+00:00

    Hello Tengku Aiman

    Thank you for reaching out to the Microsoft Q&A forum. 

    When investigated we see that you can absolutely pull the same “Compliance details” you see in the portal by querying the Policy Insights data via Azure Resource Graph or PowerShell. Under the covers, the portal is hitting the Microsoft.PolicyInsights/policyStates resource, so you can do the same yourself.

    Azure CLI / Resource Graph example

    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 (field / currentValue / targetValue).

    PowerShell example

    # Requires Az.PolicyInsights module
    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}}
    

    If you just want summary counts or to pivot by resource type/location, you can adapt these Kusto queries against the same PolicyStates index in Resource Graph.

    Hope this helps you automate pulling the exact same compliance-reason details you see in the portal!

    References


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.