Azure 资源锁 - 被 Powershell Remove-AzureVM 绕过

Azure Resource Lock - Bypassed by Powershell Remove-AzureVM

在我的 Azure 订阅中...

使用 Powershell 为 CLASSIC 资源组创建了一个新的资源组 LOCK。 New-AzureRmResourceLock -LockLevel CanNotDelete -LockName MYRG_DeleteLock -ResourceGroupName MYRG

我在此资源组中有一个 CLASSIC Stoage 帐户和一个 CLASSIC VM。 正如预期的那样,当我尝试从 Azure 门户删除 VM 时,它保护了删除并通知 "Failed to delete the VM".

但是当我使用下面的 POWERSHELL 命令时,它只是绕过资源组上的锁将其删除。 删除-AzureVM -DeleteVHD -ServiceName MYSERVICE -Name MYVM

我是否遗漏了任何步骤?

Remove-AzureVM Cmdlet 用于使用 Azure Service Management API 管理经典资源,但不知道 Azure Resource Manager (ARM)。管理锁是 ARM 的一部分。这就是为什么当您调用 Remove-AzureVM 时,它忽略了对资源组的锁定(只是因为它不知道这样的事情)并删除了 VM。