Edit

Share via


Get-AzPolicyAssignment

Gets policy assignments.

Syntax

Default (Default)

Get-AzPolicyAssignment
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Name

Get-AzPolicyAssignment
    -Name <String>
    [-Scope <String>]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

PolicyDefinitionId

Get-AzPolicyAssignment
    -PolicyDefinitionId <String>
    [-Scope <String>]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

IncludeDescendent

Get-AzPolicyAssignment
    [-Scope <String>]
    [-IncludeDescendent]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Scope

Get-AzPolicyAssignment
    -Scope <String>
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Id

Get-AzPolicyAssignment
    -Id <String>
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Description

The Get-AzPolicyAssignment cmdlet gets all policy assignments or particular assignments. Identify a policy assignment to get by name and scope or by ID.

Examples

Example 1: Get all policy assignments

Get-AzPolicyAssignment

This command gets all the policy assignments.

Example 2: Get a specific policy assignment

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
Get-AzPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceGroup.ResourceId

The first command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet and stores it in the $ResourceGroup variable. The second command gets the policy assignment named PolicyAssignment07 for the scope that the ResourceId property of $ResourceGroup identifies.

Example 3: Get all policy assignments assigned to a management group

$mgId = 'myManagementGroup'
Get-AzPolicyAssignment -Scope "/providers/Microsoft.Management/managementgroups/$mgId"

The first command specifies the ID of the management group to query. The second command gets all of the policy assignments that are assigned to the management group with ID 'myManagementGroup'.

Example 4: Get the scope, policy set definition identifier, and display name of all policy assignments formatted as a list

Get-AzPolicyAssignment | Select-Object -Property Scope, PolicyDefinitionID, DisplayName | Format-List

This command is useful when you need to find the reader-friendly DisplayName property of an Azure Policy assignment.

Example 5: [Backcompat] Get the scope, policy set definition identifier, and display name of all policy assignments formatted as a list

Get-AzPolicyAssignment -BackwardCompatible | Select-Object -ExpandProperty properties | Select-Object -Property Scope, PolicyDefinitionID, DisplayName | Format-List

This command is useful when you need to find the reader-friendly DisplayName property of an Azure Policy assignment.

Parameters

-BackwardCompatible

Causes cmdlet to return artifacts using legacy format placing policy-specific properties in a property bag object.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.

Parameter properties

Type:PSObject
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzureRMContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Id

The ID of the policy assignment to get. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:ResourceId, PolicyAssignmentId

Parameter sets

Id
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-IncludeDescendent

Causes the list of returned policy assignments to include all assignments related to the given scope, including those from ancestor scopes and those from descendent scopes. If not provided, only assignments at and above the given scope are included.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

IncludeDescendent
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

The name of the policy assignment to get.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:PolicyAssignmentName

Parameter sets

Name
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PolicyDefinitionId

Get all policy assignments that target the given policy definition [fully qualified] ID.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

PolicyDefinitionId
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Scope

The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

Name
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
PolicyDefinitionId
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
IncludeDescendent
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

SwitchParameter

String

Outputs

IPolicyAssignment