Delete an ARM VHD that is no longer needed?
Learn how to delete VHDs from ARM that are no longer needed.
June 19, 2016
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 -Container 'vhds' -Context $
About the Author
You May Also Like