Unable to delete managed disk

Martin Brown 11 Reputation points

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,513 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.
594 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Manu Philip 17,271 Reputation points MVP

    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.


    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.


    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