Search code examples
azure-powershellazure-policy

How to get Azure Policy compliance report using PowerShell for a specific Resource and for a specific policy?


I want to get the Azure Policy Compliance report for a particular resource and for a particular policy. How to achieve this using PowerShell? e.g. for a Azure VM and for a custom policy "Deny-Firewall".


Solution

  • If you want to get the Azure Policy Compliance data with PowerShell, please refer to the following script

    1. Get data for a particular policy
    # 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 data for a particular resource

    # get the policy compliance status
     Get-AzPolicyState -ResourceId <>
    
    # get the policy evaluation result
    Get-AzPolicyEvent -ResourceId <>
    

    For more details, please refer to here