When you use the built-in Hyper-V tools (Hyper-V Manager and PowerShell) to delete a virtual machine, all of its virtual hard disks are still exist. This is by design and is logically sound. This guide will walk you through the steps to delete a virtual hard disk from a cluster shared volume that can not be deleted.
There are a few ways that this problem may occur. All of these conditions will be applicable, but the way that you encounter them is different.
Symptom 1: Cannot Delete a VHDX on a CSV Using Windows Explorer on the CSV’s Owner Node
When using Windows Explorer to try to delete the file from the node that own the CSV, you receive the error: The action can’t be completed because the file is open in System. Close the file and try again.
Note: this message does sometimes appear on non-owner nodes.
Symptom 2: Cannot Delete a VHDX on a CSV Using Windows Explorer on a Non-Owning Node
When using Windows Explorer to try to delete the file from a node other than the CSV’s owner, you receive the error: The action can’t be completed because the file is open in another program. Close the file and try again.
Note: non-owning nodes do sometimes receive the “System” message from symptom 1.
Symptom 3: Cannot Delete a VHDX on a CSV Using PowerShell
The error is always the same from PowerShell whether you are on the owning node or not: Cannot remove item virtualharddisk.vhdx: The process cannot access the file ‘virtualharddisk.vhdx’ because it is being used by another process.
Symptom 4: Cannot Delete a VHDX on a CSV Using the Command Prompt
The error message from a standard command prompt is almost identical to the message that you receive in PowerShell: The process cannot access the file because it is being used by another process.
Open an elevated PowerShell prompt on the owner node and issue Dismount-DiskImage:
Dismount-DiskImage -ImagePath 'C:\ClusterStorage\CSV1\Virtual Hard Disks\virtualharddisk.vhdx'
You do not need to type out the -ImagePath parameter name but you must fully qualify the path! If you try to use a relative path with Dismount-DiskImage or any of the other disk image manipulation cmdlets, you will be told that The system cannot find the file specified:
You can also use Failover Cluster Manager, on the Storage/Disks node: