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 – http://go.microsoft.com/fwlink/p/?LinkID=320376
  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
    https://i2.wp.com/wh0k9q.dm2301.livefilestore.com/y2p88s_JolYNuSUceBbbAXVf9z9soDaj9wjgMtOnzxCYmclLnif-3J5kBbkGzeqykwnl_7TJdMo45DI_RjNL_DklMJStt9ZOObVAnZ0HG75Zf3cc6DISQsfr5SIsqYg--z2Zz8SxepxctR1SvZW-MrQRg/01-MySubscriptions.png?w=1200&ssl=1
  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.
    https://i1.wp.com/wh0k9q.dm2301.livefilestore.com/y2pUFNOdXWfAoHSMMN9Z6AJFzy3dh8kMBw-tqBsHs6UO_s1pVQCGvIsXe_0qQ_IpN8YYiP19o9yVwYvghtnFVxfvwjvMQzsflCijMxFGrcK79vd0er7CV8xh78QOqzaRRm_dXAnEfcfPsR4Vm2ovp5CmA/02-DiskURLPowerShell.png?w=1200&ssl=1
    Or, if you want to break down and use a GUI, you can find it int he browser.
    https://i2.wp.com/wh0k9q.dm2301.livefilestore.com/y2py2Jyj09VEQ_Sk7aTw7cIyABXSaLdw90vj6w1kackZgmxOOi1wrVMZgjEBoAvhfSqYoAHW_nv1T7x4Uz8swpOVn0c1LcuWMbp2zPe-68ihVOnJYPdihQNIndOdha6hIf17PmAmPNlTTpdA0jyH98Ezw/02-DiskURL.png?w=1200&ssl=1
    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 “https://intelliginkpremium.blob.core.windows.net/vhds/ds3-data-1024.vhd”} 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.