Get-AzPolicyAssignment
Gets policy assignments.
Note
This is the previous version of our documentation. Please consult the most recent version for up-to-date information.
Syntax
Get-AzPolicyAssignment
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyAssignment
[-Name <String>]
[-Scope <String>]
[-PolicyDefinitionId <String>]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyAssignment
[-Scope <String>]
[-IncludeDescendent]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyAssignment
-Id <String>
[-PolicyDefinitionId <String>]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<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'.
Parameters
Specifies the version of the resource provider API to use. If you do not specify a version, this cmdlet uses the latest available version.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
The credentials, account, tenant, and subscription used for communication with azure
| Type: | IAzureContextContainer |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Specifies the fully qualified resource ID for the policy assignment that this cmdlet gets.
| Type: | String |
| Aliases: | ResourceId |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
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.
| Type: | SwitchParameter |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the name of the policy assignment that this cmdlet gets.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the ID of the policy definition of the policy assignments that this cmdlet gets.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Indicates that this cmdlet considers pre-release API versions when it automatically determines which version to use.
| Type: | SwitchParameter |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Specifies the scope at which the policy is applied for the assignment that this cmdlet gets.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |