Hyper-V: Can’t delete Virtual Machine with ‘Operation cannot be performed while the object in current state’
There are situations, especially when running your virtual infrastructure on Storage Area Networks (SANs), that you are unable to effectively delete a virtual machine. There are many reasons why your VM is no longer needed such as you’ve moved to another farm or you simply don’t need the virtual machine in cases when you are using dynamic provisioning. There is nothing more frustrated than effectively deleting a virtual machine in Virtual Machine Manager (VMM) and have it auto-discover it right back because the virtual machine still has “remnants” on the Hyper-V host. This post will, hopefully, help you eliminate this situation and clear up your host and your VMM infrastructure.
Delete Fails in MMC & Hyper-V-VMMS Source Errors in Event Viewer
You’ve noticed a “straggler” left behind in your SCVMM console and you attempt to delete it and VMM says no thank you. You can’t repair (which you expected since the files are gone, etc.) nor can you force it to delete.
You then head to the local Hyper-V host and open the Hyper-V manager and quickly see that the virtual machine is in a un-manageable state. Since you know the VM isn’t needed any longer, you right-click and attempt to delete it and receive the following error -
The next step that most Windows administrators will do (except for maybe searching the web using Bing) is view the Event Viewer (Custom Views –> Roles –> Hyper-V.) You immediately notice a lot of errors similar to the following for the VM you are attempting to delete -
Clean up – Getting rid of the Rotten “Apple” e.g. Virtual Machine
The key reason you are probably reading this is to help you solve your problem. Thus, I will get on with the resolution that recently solved my problem that took me awhile to figure out (with help, of course). To resolve this problem, do the following:
- Connect to your Hyper-V Server
- Open Windows Explorer
- Open the path %systemroot%\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines (NOTE: This is a hidden folder and requires Operating System files to be displayed)
- You will notice a set of XML documents, one for each Virtual Machine on this host. locate the one with the same matching GUID from your event viewer message as outlined below -
- Right-click on the XML file with the same GUID, and select delete
- Close Windows Explorer
- Open Hyper-V MMC console
- Notice that the virtual machine is gone…
Cleaning up Virtual Machine Manager
After you’ve finally rid yourself of this beast of a virtual machine who wouldn’t go down without a fight, you will need to then cleanup VMM. The nice thing is that it is really simple as VMM will almost instantly determine that this virtual machine is now missing and you can do the famous delete and it will succeed.
To delete it, simply right-click and select delete -
When you have virtual machines that are in a “Failed” state it is very frustrating. Because of this, I felt the need to post today to share some insight how you can make VMs go away that you really, seriously, want to go away. I hope this post has been helpful in getting your VMM/Hyper-V farm back to a beautiful green…(as in, working perfectly!)