azure policy exemption list using powershell/cli t

Ankita Rani Patro 181 Reputation points
2022-05-27T17:54:26.577+00:00

My client has 200 azure policy exemption applied to different resource group. I am looking for a powershell command to list all per scope. But I see Get-AzPolicyExemption is not listing out all policies . It only lists the current subscription. But I need all list.

I need help to get a list of azure policy exemption list.

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
960 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sudipta Chakraborty - MSFT 1,111 Reputation points Microsoft Employee
    2022-05-27T18:35:30.19+00:00

    anonymous user :

    You can try out the following powershell script to get the desired results:

    $SubscriptionList = Get-AzSubscription  
    $collectionWithItems = New-Object System.Collections.ArrayList  
      
    Foreach ($subscription in $SubscriptionList)  
    {  
        Write-Host $subscription.Name  
        Set-AzContext -SubscriptionId $subscription.Id  
        $ResourceGroupList = Get-AzResourceGroup      
      
        Foreach ($ResourceGroup in $ResourceGroupList)  
        {  
            Write-Host 'Resource Id : ' $ResourceGroup.ResourceId  
            $exemptions= Get-AzPolicyExemption -Scope $ResourceGroup.ResourceId  
      
            $temp = New-Object System.Object  
            $temp | Add-Member -MemberType NoteProperty -Name "ResourceId" -Value $ResourceGroup.ResourceId          
      
            Foreach ($exemption in $exemptions)  
            {  
                Write-Host 'Exemption : ' $exemption.Name  
                $temp | Add-Member -MemberType NoteProperty -Name "Exemption" -Value $exemption.Name  
      
                $collectionWithItems.Add($temp)  
            }  
        }  
    }  
      
      
    $collectionWithItems | Export-Csv -Path .\ExportedData.csv -NoTypeInformation  
    

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

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