flensted
flensted

Reputation: 101

Windows Azure: Delete disk attached to non-existent VM

Just found out I was taking up - and paying for - a lot of storage due to abandoned disks from long ago deleted VMs. I manged to delete most of them, but now I'm stuck with a set that cannot be deleted as they remain attached to VMs nowhere to be found.

Any ideas how to get rid of these disks, PowerShell tricks maybe?

Upvotes: 7

Views: 8759

Answers (5)

Jaanca
Jaanca

Reputation: 1

in azure you can erase disks using Azure Storage Explorer.

If you have a deleted virtual machine and the disks report that they are attached and the command gives you an error:

Remove-AzDisk -ResourceGroupName $resourcegroup -DiskName -Force output:

Remove-AzDisk: Disk vmname_OsDisk_1_c2116### is attached to VM /subscriptions/###/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vmname.

ErrorCode: OperationNotAllowed

ErrorMessage: Disk /subscriptions/###/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vmname.
ErrorTarget:
StatusCode: 409
ReasonPhrase: Conflict
OperationID : 34731d70-2f9e-4ad1-8eec-4fcb6f55fbd0

you can create a generation 1 server to test on the same resource group with the same bug name.

with this you make the "Resource ID" exist for the virtual machine,

and you can now erase the disk by Azure Storage Explorer normally.

This is because Azure does a validation prior to deletion and if the disk is attached, the VM must exist.

Upvotes: 0

MightyMeatBoots
MightyMeatBoots

Reputation: 11

In the "new" Azure portal. Select Storage Accounts, then click on the storage account" where your none used VHD's are located, Click Blobs under Services, Click vhds under Essentials, search for unwanted vhd and click delete.

Upvotes: 1

Michelle Welcks
Michelle Welcks

Reputation: 3894

I was unable to use the (2016) web portal to delete orphaned disks in my (classic) storage account. The answers here work, but here is a more detailed walk-through for deleteing these orphaned disks with PowerShell.

PowerShell

Download and install PowerShell if you haven't already. (Install and configure Azure PowerShell.) Initial steps from this doclink:

  • Check that the Azure PowerShell module is available after installing:
    Get-Module –ListAvailable

  • If the Azure PowerShell module is not listed, you may need to import it:
    Import-Module Azure

  • Login to Azure Resource Manager:
    Login-AzureRmAccount

AzurePublishSettingsFile

  • Retreive your PublishSettingsFile.
    Get-AzurePublishSettingsFile

  • Import-AzurePublishSettingsFile and specify the path to the file just saved.
    Import-AzurePublishSettingsFile -PublishSettingsFile '<your file path>'

Show and Remove Disks

Upvotes: 0

Mike
Mike

Reputation: 11

The only way to do this that I can see is through PowerShell. I ran into the same problem and here's how I fixed it. I installed the Azure PowerShell extensions and configured my subscription and then my storage account. Once I did that I then ran this command

get-azuredisk | Remove-AzureDisk

Get-azuredisk will grab all disks In my case I needed all of them removed. If you need to do individual then you need to get the name of the disk and then run remove-azuredisk with the name switch and specify the disk name to remove it. That fixed it for me. Hope this helps someone in the future.

Upvotes: 1

AbhishekAnand
AbhishekAnand

Reputation: 132

If I am understanding correct, Once you delete a Virtual Machine, it delete the service but keep a copy of the VHD image under Disks. So please go to the Disks tab under virtual Machine and try to delete it.

If that is not the case, please add a screenshot with error message from where your trying to delete VM.

Upvotes: 3

Related Questions