0
votes

I'm trying to get the list of all policy assignments created in azure using the below commands.

However when I scope the assignment to the resource group, below command does not return that assignment in its output. Please advise on this further.

Powershell commands:

To get all policy assignment:

Get-AzPolicyAssignment

This commands return list of assignments scoped to only subscriptions & management groups

To get specific policy assignment which is scoped to resource group:

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup01'
Get-AzPolicyAssignment -Name 'PolicyAssignment01' -Scope $ResourceGroup.ResourceId

This commands does not return any policy assignment

Reference links:

  1. https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/get-azurermpolicyassignment?view=azurermps-6.13.0

  2. https://docs.microsoft.com/en-us/powershell/module/az.resources/get-azpolicyassignment?view=azps-5.4.0

1
COuld you please check if you have assigned the policy to the group? - Jim Xu
Could you please tell me how you assign policy? - Jim Xu

1 Answers

0
votes

The command looks correct.

PS C:\> $ResourceGroup = Get-AzResourceGroup -Name '<RESOURCE GROUP>'
PS C:\> Get-AzPolicyAssignment -Name '<Policy Name>' -Scope $ResourceGroup.ResourceId

Two things to check :

  1. $ResourceGroup

You could check whether there is value stored in the object.

  1. You could run Get-AzPolicyAssignment -scope $ResourceGroup.ResourceId

You could see all policies assigned for the resource group. And cross check whether you have the required policy name from the output.