Edit

Share via


Remove-AzPolicyAssignment

This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.

Syntax

Name (Default)

Remove-AzPolicyAssignment
    -Name <String>
    [-Scope <String>]
    [-Force]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Id

Remove-AzPolicyAssignment
    -Id <String>
    [-Force]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

InputObject

Remove-AzPolicyAssignment
    -InputObject <IPolicyIdentity>
    [-Force]
    [-BackwardCompatible]
    [-DefaultProfile <PSObject>]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.

Examples

Example 1: Remove policy assignment by name and scope

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
Remove-AzPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceGroup.ResourceId -Force

The first command gets a resource group named ResourceGroup11 by using the Get-AzResourceGroup cmdlet. The command stores that object in the $ResourceGroup variable. The second command removes the policy assignment named PolicyAssignment07 that was assigned at a resource group level. The ResourceId property of $ResourceGroup identifies the resource group.

Example 2: Remove policy assignment by ID

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$PolicyAssignment = Get-AzPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceGroup.ResourceId
Remove-AzPolicyAssignment -Id $PolicyAssignment.Id -Confirm:$false

The first command gets a resource group named ResourceGroup11, and then stores that object in the $ResourceGroup variable. The second command gets the policy assignment at a resource group level, and then stores it in the $PolicyAssignment variable. The ResourceId property of $ResourceGroup identifies the resource group. The final command removes the policy assignment that the ResourceId property of $PolicyAssignment identifies.

Example 3: [Backcompat] Remove policy assignment by ID

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$PolicyAssignment = Get-AzPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceGroup.ResourceId -BackwardCompatible
Remove-AzPolicyAssignment -Id $PolicyAssignment.ResourceId -Confirm:$false -BackwardCompatible
True

The first command gets a resource group named ResourceGroup11, and then stores that object in the $ResourceGroup variable. The second command gets the policy assignment at a resource group level, and then stores it in the $PolicyAssignment variable. The ResourceId property of $ResourceGroup identifies the resource group. The final command removes the policy assignment that the ResourceId property of $PolicyAssignment identifies.

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

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

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

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.

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

-Force

When $true, skip confirmation prompts

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

-Id

The ID of the policy assignment to delete. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.

Parameter properties

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

Parameter sets

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

-InputObject

Identity Parameter To construct, see NOTES section for INPUTOBJECT properties and create a hash table.

Parameter properties

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

Parameter sets

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

-Name

The name of the policy assignment to delete.

Parameter properties

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

Parameter sets

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

-PassThru

Returns true when the command succeeds

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

-Scope

The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'

Parameter properties

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

Parameter sets

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

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

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

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
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

IPolicyIdentity

String

Outputs

Boolean