Unable to delete managed disk

Martin Brown 11 Reputation points
2020-06-19T19:57:09.877+00:00

I'm trying to deploy a VM to Azure using an arm template deployed using Azure Pipelines. I ran the deployment once without error, then I made a change to the template and ran it again. This time it failed because the VM already existed. I deleted the resource group that the VM is in and ran the deployment again. This time it failed with the error:

Disk test-vm-os-disk already exists in resource group TEST-RG.

I've tried deleting the test-rg group and redeploying but am still getting the error. I ran the following PowerShell script:

get-azdisk | where Name -eq test-vm-os-disk
remove-azdisk -ResourceGroup test-rg -Name test-vm-os-disk
get-azdisk | where Name -eq test-vm-os-disk

The first get shows that the disk is there and DiskState is Unattached.
The remove completes successfully with the following output:

Remove-AzDisk operation
This cmdlet will remove the specified resource. Do you want to continue?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y

Name :
StartTime : 19/06/2020 20:49:42
EndTime : 19/06/2020 20:49:50
Status : Succeeded
Error :

The second get shows the disk is still there with the attributes unchanged.

Any ideas?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,479 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
590 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Manu Philip 17,266 Reputation points MVP
    2020-06-19T23:02:50.783+00:00

    Hello @mgbrown,

    As the VM instance has been deleted, the disks are not at all associated with the VM and the command can't work. So, just try Get-AzDisk and find the unattached disk and delete manually. Or please find the Microsoft documentation explaining the way to delete it.

    https://video2.skills-academy.com/en-us/azure/virtual-machines/windows/find-unattached-disks

    Next time, I am suggesting yo to refer my blog, in which I have an article to handle this situation. Copy the script as .ps1 file and execute it in PowerShell. Just input the VM name and the script can clean all the resources associated. The script creates necessary labels and attach to the disk before the VM deletion, and delete works well by referring the special labels.

    http://cloudcompute.info/delete-azure-vm-and-all-associated-resources-using-powershell-script/

    Please mark as "Accept the answer" if the above steps helps you. Others with similar issues can also follow the solution as per your suggestion

    Regards,

    Manu