Edit

Remove-AzPolicyEnrollment

Deletes a policy enrollment.

Syntax

DeleteByNameAndScope (Default)

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

DeleteById

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

DeleteByInputObject

Remove-AzPolicyEnrollment
    -InputObject <IPolicyEnrollment>
    [-Force]
    [-DefaultProfile <PSObject>]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Remove-AzPolicyEnrollment cmdlet deletes a policy enrollment, given its name and the scope it was created in. The scope of a policy enrollment is the part of its ID preceding '/providers/Microsoft.Authorization/policyEnrollments/{policyEnrollmentName}'.

Examples

Example 1: Remove policy enrollment by name and scope

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
Remove-AzPolicyEnrollment -Name 'PolicyEnrollment07' -Scope $ResourceGroup.ResourceId -Confirm

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 enrollment named PolicyEnrollment07 at the resource group scope. The ResourceId property of $ResourceGroup identifies the resource group.

Example 2: Remove policy enrollment by ID

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
$PolicyEnrollment = Get-AzPolicyEnrollment -Name 'PolicyEnrollment07' -Scope $ResourceGroup.ResourceId
Remove-AzPolicyEnrollment -Id $PolicyEnrollment.Id -Force

The first command gets a resource group named ResourceGroup11, and then stores that object in the $ResourceGroup variable. The second command gets the policy enrollment at a resource group level, and then stores it in the $PolicyEnrollment variable. The ResourceId property of $ResourceGroup identifies the resource group. The final command removes the policy enrollment that the Id property of $PolicyEnrollment identifies, bypassing the confirmation prompt with the Force parameter.

Parameters

-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 enrollment to delete. Use the format '{scope}/providers/Microsoft.Authorization/policyEnrollments/{policyEnrollmentName}'.

Parameter properties

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

Parameter sets

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

-InputObject

The policy enrollment object to delete.

Parameter properties

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

Parameter sets

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

-Name

The name of the policy enrollment.

Parameter properties

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

Parameter sets

DeleteByNameAndScope
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 enrollment. 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

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

IPolicyEnrollment

String

Outputs

Boolean