The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are
advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and
updates.
Although the AzureRM module may still function, it's no longer maintained or supported, placing
any continued use at the user's discretion and risk. Please refer to our
migration resources for guidance on transitioning to the Az module.
The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The second command gets the policy definition named VirtualMachinePolicy by using the Get-AzureRmPolicyDefinition cmdlet and stores it in the $Policy variable.
The final command assigns the policy in $Policy at the level of the resource group identified by the ResourceId property of $ResourceGroup.
Example 2: Policy assignment at resource group level with policy parameter object
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 built-in policy definition for allowed locations by using the Get-AzureRmPolicyDefinition cmdlet.
The command stores that object in the $Policy variable.
The third and fourth commands create an object containing all Azure regions with "east" in the name.
The commands store that object in the $AllowedLocations variable.
The final command assigns the policy in $Policy at the level of a resource group using the policy parameter object in $AllowedLocations.
The ResourceId property of $ResourceGroup identifies the resource group.
Example 3: Policy assignment at resource group level with policy parameter file
Create a file called AllowedLocations.json in the local working directory with the following content.
The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The second command gets the built-in policy definition for allowed locations by using the Get-AzureRmPolicyDefinition cmdlet and stores it in the $Policy variable.
The final command assigns the policy in $Policy at the resource group identified by the ResourceId property of $ResourceGroup using the policy parameter file AllowedLocations.json from the local working directory.
Example 4: Policy assignment with a managed identity
The first command gets a resource group named ResourceGroup11 by using the Get-AzureRMResourceGroup cmdlet and stores it in the $ResourceGroup variable.
The second command gets the policy definition named VirtualMachinePolicy by using the Get-AzureRmPolicyDefinition cmdlet and stores it in the $Policy variable.
The final command assigns the policy in $Policy to the resource group. A managed identity is automatically created and assigned to the policy 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.
Generate and assign a Microsoft Entra identity for this policy assignment. The identity will be used when executing deployments for 'deployIfNotExists' policies. Location is required when assigning an identity.
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
A hash table which represents SKU properties. Defaults to the Free SKU with the values: @{Name = 'A0'; Tier = 'Free'}. To use the Standard SKU, use the values: @{Name = 'A1'; Tier = 'Standard'}.
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.