Edit

Share via


Get-AzPolicyDefinition

Gets policy set definitions.

Syntax

Name (Default)

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

ManagementGroupName

Get-AzPolicyDefinition
    -ManagementGroupName <String>
    [-Name <String>]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

SubscriptionId

Get-AzPolicyDefinition
    -SubscriptionId <String>
    [-Name <String>]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Version

Get-AzPolicyDefinition
    -Version <String>
    [-Name <String>]
    [-Id <String>]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

ListVersion

Get-AzPolicyDefinition
    [-Name <String>]
    [-Id <String>]
    [-ListVersion]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Id

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

Builtin

Get-AzPolicyDefinition
    [-SubscriptionId <String>]
    [-ManagementGroupName <String>]
    [-Builtin]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Custom

Get-AzPolicyDefinition
    [-SubscriptionId <String>]
    [-ManagementGroupName <String>]
    [-Custom]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Static

Get-AzPolicyDefinition
    [-SubscriptionId <String>]
    [-ManagementGroupName <String>]
    [-Static]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [<CommonParameters>]

Description

The Get-AzPolicyDefinition cmdlet gets a collection of policy set definitions or a specific policy set 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 -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.

Example 7: [Backcompat] Get the display name, description, policy type, and metadata of all policy definitions formatted as a list

Get-AzPolicyDefinition -BackwardCompatible | 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

-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

-Builtin

Causes cmdlet to return only built-in policy definitions.

Parameter properties

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

Parameter sets

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

-Custom

Causes cmdlet to return only custom policy definitions.

Parameter properties

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

Parameter sets

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

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

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 full Id of the policy definition to get.

Parameter properties

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

Parameter sets

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

-ListVersion

Causes cmdlet to return only custom policy definitions.

Parameter properties

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

Parameter sets

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

-ManagementGroupName

The name of the management group.

Parameter properties

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

Parameter sets

ManagementGroupName
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 definition to get.

Parameter properties

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

Parameter sets

Name
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ManagementGroupName
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
SubscriptionId
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
Version
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ListVersion
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Static

Causes cmdlet to return only static policy definitions.

Parameter properties

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

Parameter sets

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

-SubscriptionId

The ID of the target subscription.

Parameter properties

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

Parameter sets

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

-Version

The policy definition version in #.#.# format.

Parameter properties

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

Parameter sets

Version
Position:Named
Mandatory:True
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

IPolicyDefinition