New-​Azure​Rm​Policy​Assignment

Creates a policy assignment.

Syntax

New-AzureRmPolicyAssignment
   [-ApiVersion <String>]
   [-DisplayName <String>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   -Name <String>
   -PolicyDefinition <PSObject>
   -PolicyParameter <String>
   [-Pre]
   -Scope <String>
   [<CommonParameters>]
New-AzureRmPolicyAssignment
   [-ApiVersion <String>]
   [-DisplayName <String>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   -Name <String>
   -PolicyDefinition <PSObject>
   -PolicyParameterObject <Hashtable>
   [-Pre]
   -Scope <String>
   [<CommonParameters>]

Description

The New-AzureRmPolicyAssignment cmdlet creates a policy assignment. Specify a policy and scope.

Examples

Example 1: Policy assignment at resource group level

PS C:\>$ResourceGroup = Get-AzureRmResourceGroup -Name "ResourceGroup11"
PS C:\> $Policy = Get-AzureRmPolicyDefinition -Name "VirtualMachinePolicy"
PS C:\> New-AzureRmPolicyAssignment -Name "VirtualMachinePolicyAssignment" -PolicyDefinition $Policy -Scope $ResourceGroup.ResourceId

The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdlet. The command stores that object in the $ResourceGroup variable.

The second command gets the policy definition named VirtualMachinePolicy by using the Get-AzureRmPolicyDefinition cmdlet. The command stores that object in the $Policy variable.

The final command assigns the policy in $Policy at the level of a resource group. The ResourceId property of $ResourceGroup identifies the resource group.

Required Parameters

-Name

Specifies a name for the policy assignment.

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

Specifies a policy, as a PSObject object that contains the policy rule.

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

The policy parameter file path or policy parameter string.

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

The policy parameter object.

Type:Hashtable
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Scope

Specifies the scope at which to assign the policy. For instance, to assign a policy to a resource group, specify the following:

/subscriptions/subscription ID/resourcegroups/resource group name

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

Optional 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
-DisplayName

Specifies a display name for the policy assignment.

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

Specifies how this cmdlet responds to an information event.

The acceptable values for this parameter are:

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InformationVariable

Specifies an information variable.

Type:String
Aliases:iv
Position:Named
Default value:None
Accept pipeline input:False
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