When you delete a VM via Microsoft Azure portal, you don’t have an option to delete the VM related objects (virtual network interfaces and virtual disks as well) .
Orphaned virtual disks – these are
*.vhd files that reside on your StorageAccount(s) and consume expensive storage space, but are not related to any VM.
As always, the Mr. PowerShell will help us in this task. I will also show you a method to remove/delete these disks!
Introduce to you my next function
Get-AzOrphanedVhd from my Azure Automation Az-Module which will find all your orphaned disks in all
ResourceGroups on all
- This simple function has no parameters at all!
All you need to start using it, is to login to your Azure account, select your target subscription and just run the
Login-AzureRmAccount Select-AzureRmSubscription Get-AzOrphanedVhd
- You can skip the first two steps if you are using my New-AzCredProfile function. Open PowerShell console and run the function. Can it be even simpler?
- All properties, returned by the function are self-explained. Two properties only I want to note.
|LastWriteDays||Days gone since the disk was modified|
|Modified||Disk modification date in your! local time|
- Two environment variables
$ErrorActionPreferenceare set to
SilentlyContinueto hide these kind of warnings and error messages.
Orphaned does not mean needless
- Do remember! Even if a virtual disk is not related to any VM, this does not mean there is no valuable data on it. Think twice before you delete any virtual disk.
If you still have decided to delete some virtual disk(s), you can do it either through Azure portal UI or
Get-Help Remove-AzureStorageBlob –Full Get-Help Get-AzureStorageBlob –Full
- This example with
Select-AzObjecthelper function, described in this article, will remove a single orphaned disk.
Get-AzOrphanedVhd VHD : vm1.vhd StorageAccount : teststg001lrsp … Select-AzObject SA | Get-AzureStorageContainer | Get-AzureStorageBlob -Blob vm1.vhd | Remove-AzureStorageBlob -Confirm:$true
vm1.vhdis orphaned VHD, returned by
Get-AzOrphanedVhdthat you want to delete.
Choice from menu the StorageAccount, returned by
StorageAccountproperty for your disk.
To avoid accidental disk removing always use the
Remove-AzureStorageBlobcmdlet together with
- For more details about the function, please take a look at the content based help and examples.
Get-Help Get-AzOrphanedVhd -Full Get-Help Get-AzOrphanedVhd -Examples