Search code examples
azurepowershellresourcesazure-resource-lock

Azure Resource Lock - Bypassed by Powershell Remove-AzureVM


In my Azure Subscription...

Created a new Resource Group LOCK using Powershell for a CLASSIC Resource Group. New-AzureRmResourceLock -LockLevel CanNotDelete -LockName MYRG_DeleteLock -ResourceGroupName MYRG

I have a CLASSIC Stoage Account and a CLASSIC VM within this Resource Group. As expected, when I tried deleting the VM from the Azure Portal it PROTECTED the deletion and notified that "Failed to delete the VM".

But when I used the below POWERSHELL command it just deleted it BYPASSING the lock on the RESOURCE GROUP. Remove-AzureVM -DeleteVHD -ServiceName MYSERVICE -Name MYVM

Am I missing any steps?


Solution

  • Remove-AzureVM Cmdlet is for managing classic resources using Azure Service Management API that has no idea about Azure Resource Manager (ARM). Management locks are part of ARM. This is why when you called Remove-AzureVM, it ignored the lock on the resource group (simply because it is not aware of such a thing) and deleted the VM.