Set-AzPolicyDefinition

Modifies a policy definition.

Syntax

Set-AzPolicyDefinition
   -Name <String>
   [-DisplayName <String>]
   [-Description <String>]
   [-Policy <String>]
   [-Metadata <String>]
   [-Parameter <String>]
   [-Mode <String>]
   [-ApiVersion <String>]
   [-Pre]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzPolicyDefinition
   -Name <String>
   [-DisplayName <String>]
   [-Description <String>]
   [-Policy <String>]
   [-Metadata <String>]
   [-Parameter <String>]
   [-Mode <String>]
   -ManagementGroupName <String>
   [-ApiVersion <String>]
   [-Pre]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzPolicyDefinition
   -Name <String>
   [-DisplayName <String>]
   [-Description <String>]
   [-Policy <String>]
   [-Metadata <String>]
   [-Parameter <String>]
   [-Mode <String>]
   -SubscriptionId <Guid>
   [-ApiVersion <String>]
   [-Pre]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzPolicyDefinition
   -Id <String>
   [-DisplayName <String>]
   [-Description <String>]
   [-Policy <String>]
   [-Metadata <String>]
   [-Parameter <String>]
   [-Mode <String>]
   [-ApiVersion <String>]
   [-Pre]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The Set-AzPolicyDefinition cmdlet modifies a policy definition.

Examples

Example 1: Update the description of a policy definition

PS C:\> $PolicyDefinition = Get-AzPolicyDefinition -Name 'VMPolicyDefinition'
PS C:\> Set-AzPolicyDefinition -Id $PolicyDefinition.ResourceId -Description 'Updated policy to not allow virtual machine creation'

The first command gets a policy definition named VMPolicyDefinition by using the Get-AzPolicyDefinition cmdlet. The command stores that object in the $PolicyDefinition variable. The second command updates the description of the policy definition identified by the ResourceId property of $PolicyDefinition.

Example 2: Update the mode of a policy definition

PS C:\> Set-AzPolicyDefinition -Name 'VMPolicyDefinition' -Mode 'All'

This command updates the policy definition named VMPolicyDefinition by using the Set-AzPolicyDefinition cmdlet to set its mode property to 'All'.

Example 3: Update the metadata of a policy definition

PS C:\> Set-AzPolicyDefinition -Name 'VMPolicyDefinition' -Metadata '{"category":"Virtual Machine"}'


Name               : VMPolicyDefinition
ResourceId         : /subscriptions/11111111-1111-1111-1111-111111111111/providers/Microsoft.Authorization/policyDefinitions/VMPolicyDefinition
ResourceName       : VMPolicyDefinition
ResourceType       : Microsoft.Authorization/policyDefinitions
SubscriptionId     : 11111111-1111-1111-1111-111111111111
Properties         : @{displayName=VMPolicyDefinition; policyType=Custom; mode=All; metadata=; policyRule=}
PolicyDefinitionId : /subscriptions/11111111-1111-1111-1111-111111111111/providers/Microsoft.Authorization/policyDefinitions/VMPolicyDefinition

This command updates the metadata of a policy definition named VMPolicyDefinition to indicate its category is "Virtual Machine".

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
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Description

Specifies a new description for the policy definition.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-DisplayName

Specifies a new display name for the policy definition.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Id

Specifies the fully qualified resource ID for the policy definition that this cmdlet modifies.

Type:String
Aliases:ResourceId
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ManagementGroupName

The name of the management group of the policy definition to update.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Metadata

The metadata for policy definition. This can either be a path to a file name containing the metadata, or the metadata as string.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Mode

The mode of the new policy definition.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Name

Specifies the name of the policy definition that this cmdlet modifies.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Parameter

The parameters declaration for policy definition. This can either be a path to a file name or uri containing the parameters declaration, or the parameters declaration as string.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Policy

Specifies new policy rule for the policy definition. You can specify the path of a .json file or a string that contains the policy in JavaScript Object Notation (JSON) format.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
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
Accept pipeline input:False
Accept wildcard characters:False
-SubscriptionId

The subscription ID of the policy definition to update.

Type:System.Nullable`1[System.Guid]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Inputs

String

System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

Outputs

PSObject