Get-AzPolicyDefinition
Gets policy definitions.
Syntax
Get-AzPolicyDefinition
[-Name <String>]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyDefinition
[-Name <String>]
-ManagementGroupName <String>
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyDefinition
[-Name <String>]
-SubscriptionId <Guid>
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyDefinition
-Id <String>
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyDefinition
[-ManagementGroupName <String>]
[-SubscriptionId <Guid>]
[-Builtin]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzPolicyDefinition
[-ManagementGroupName <String>]
[-SubscriptionId <Guid>]
[-Custom]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Get-AzPolicyDefinition cmdlet gets a collection of policy definitions or a specific policy definition identified by name or ID.
Examples
Example 1: Get all policy definitions
Get-AzPolicyDefinition
This command gets all the policy definitions.
Example 2: Get policy definition from current subscription by name
Get-AzPolicyDefinition -Name 'VMPolicyDefinition'
This command gets the policy definition named VMPolicyDefinition from the current default subscription.
Example 3: Get policy definition from management group by name
Get-AzPolicyDefinition -Name 'VMPolicyDefinition' -ManagementGroupName 'Dept42'
This command gets the policy definition named VMPolicyDefinition from the management group named Dept42.
Example 4: Get all built-in policy definitions from subscription
Get-AzPolicyDefinition -SubscriptionId '3bf44b72-c631-427a-b8c8-53e2595398ca' -Builtin
This command gets all built-in policy definitions from the subscription with ID 3bf44b72-c631-427a-b8c8-53e2595398ca.
Example 5: Get policy definitions from a given category
Get-AzPolicyDefinition | Where-Object {$_.Properties.metadata.category -eq 'Tags'}
This command gets all policy definitions in the category Tags.
Example 6: Get the display name, description, policy type, and metadata of all policy definitions formatted as a list
Get-AzPolicyDefinition | Select-Object -ExpandProperty properties | Select-Object -Property DisplayName, Description, PolicyType, Metadata | Format-List
This command is useful when you need to find the reader-friendly DisplayName property of an Azure Policy definition. You can parse the Metadata property to discover the policy definition's version number and category assignment.
Parameters
-ApiVersion
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 |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Builtin
Limits list of results to only built-in policy definitions.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Custom
Limits list of results to only custom policy definitions.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure
Type: | IAzureContextContainer |
Aliases: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Id
Specifies the fully qualified resource ID for the policy definition that this cmdlet gets.
Type: | String |
Aliases: | ResourceId |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ManagementGroupName
The name of the management group of the policy definition(s) to get.
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
Specifies the name of the policy definition that this cmdlet gets.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Pre
Indicates that this cmdlet considers pre-release API versions when it automatically determines which version to use.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SubscriptionId
The subscription ID of the policy definition(s) to get.
Type: | Nullable<T>[Guid] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
Nullable<T>[[System.Guid, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]