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

image Click to enlarge

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:

  1. Download the Azure PowerShell commandlets and install from here:
  2. Start, Search, type PowerShell right click on it and “run as Administrator”.
  3. Run Get-AzurePublishSettingsFile which will launch a browser window to Azure where you will download the published settings file. Save it to c:\temp.
  4. Run Import-AzurePublishSettingsFile to import the certificate and subscription information. Import-AzurePublishSettingsfile c:\temp\your-filename.publishsettings
  5. Download the script BreakLease.ps1 from the link below:
  6. Run Set-ExecutionPolicy to allow script execution: (Prompt must have admin privileges)
    Set-ExecutionPolicy unrestricted
  7. 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