When deleting a Virtual Machine in Azure I have been having a problem deleting the VHD file. I would first select the VM and choose delete. After that succeeded I would go into the storage section and browse to the VHD blob. Then when I choose to delete the VHD file and then it would give me the error “There is currently a lease on the blob and no lease ID was specified in the request”.
I originally thought this was an Azure problem. Turns out I was doing it wrong. “User error” or should the user interface should be improved?
Here is what you need to do. Click on the Virtual Machine tab on the left hand side. Now go into the DISKS tab at the top. You will see your VHD files listed there. You can’t select delete on a VHD that still have a VMWhen you choose to delete
That has let me delete a lot of the VHD files that I had in the storage but I still couldn’t delete all of them. Hunh – looks like there are some problems…
If you have the same issue as I had, then you need to break the lease and currently the tool to do that is a command line tool. Here are the details on how to do that:
How to use PowerShell script to break the Azure lease:
- Download the Azure PowerShell commandlets and install from here:
- Start, Search, type PowerShell right click on it and “run as Administrator”.
- Run Get-AzurePublishSettingsFile which will launch a browser window to Azure where you will download the published settings file. Save it to c:\temp.
- Run Import-AzurePublishSettingsFile to import the certificate and subscription information. Import-AzurePublishSettingsfile c:\temp\your-filename.publishsettings
- Download the script BreakLease.ps1 from the link below:
- Run Set-ExecutionPolicy to allow script execution: (Prompt must have admin privileges)
- Run BreakLease.ps1 with the URL to the VHD in order to break the lease. The script obtains the necessary storage account information, checks that the blob is not currently registered as a disk or as an image, then proceeds to break the current lease (if any). You find the URL in the Azure portal as below:
Hope that helps. If you use this to fix your issues – leave me a message and let me know it was useful. –Brian