Delete an ARM VHD that is no longer needed?

Delete an ARM VHD that is no longer needed?

Q. How do I delete a disk for an ARM VM that no longer exists?

A. With Azure Service Manager (ASM) there were a series of cmdlets for Azure disk management including deletion of disks which were also handled differently through the old Azure portal. Azure Resource Manager (ARM) handles disks very differently. A VM disk is actually a VHD file stored in a page blob. With ARM the management of disks is performed via the VM resource, for example the disks of a VM are accessed as follows:

$vm = Get-AzureRmVM -Name testvm -ResourceGroupName RG-SCUSA
$vm.StorageProfile

Through the StorageProfile the OSDisk and an array of DataDisks are available for management including cache configuration and resize. Data disks can be added and removed via the AzureRmVMDataDisk cmdlets to the VM. To actually delete a VHD that is not required and not connected to a VM the page blob is deleted directly. To view all the VHDs use:

Get-AzureRMStorageAccount -Name savtechsalrsscus -ResourceGroupName rg-scusa | 
Get-AzureStorageContainer | where {$_.Name -eq 'vhds'} | Get-AzureStorageBlob | where {$_.Name.EndsWith('.vhd')} 

To actually delete a file use:

Remove-AzureStorageBlob -Blob <name of the VHD> -Container 'vhds' -Context $<context to the storage account>

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish