The other day I had an issue deleting on of my VMs Old Hard Drive from Azure via the GUI in the browser. So, what did I do, my favorite, write some PowerShell.

So, just a quick post on the steps you can take if you want to delete an Azure .VHD in PowerShell.

  1. Download and Install the Microsoft Azure PowerShell from here –
  2. Once you have it downloaded, launch “Microsoft Azure PowerShell”
  3. Run the Command Add-AzureAccount You’ll receive a popup dialog box to log in to your Azure Subscription (this will work if you have Multi Factor Authentication enabled on your account)
  4. Next you need to make sure you have the correct subscription selected, if you’re like me you may have more than one. You can view all your available subscriptions by running Get-AzureSubscription
  5. From the subscription list, copy the subscription ID for the subscription that contains the disk you wish to delete.
  6. Run the command Select-AzureSubscription -SubscriptoinID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  7. If you run Get-AzureSubscription again, you’ll see the property “IsCurrent” has changed to the Azure Subscription you specified in step six.
  8. Next, get your DiskURL/MediaLink.
    You can use the command Get-AzureDisk | ft MediaLink. If you can’t pick out the disk just from the MediaLink you could use Get-AzureDisk | ft DiskName, MediaLink, IOType to help figure it out, or add/remove any other properties to the table.
    Or, if you want to break down and use a GUI, you can find it int he browser.
    Copy this URL to your clipboard. There are a few different ways to get to this location. Either through the VM itself (if it still exists), or browsing through your Azure Storage Accounts.
  9. Run the following PowerShell command $disk = Get-AzureDisk | ? {$_.MediaLink -eq “”} where the url is the URL you copied in step 8.
  10. Run the command Remove-AzureDisk -DiskName $disk.DiskName -DeleteVHD
  11. Finally, if you run the command Get-AzureDisk | ft DiskName, IOType you’ll that your VHD has been deleted from your subscription.