Hyper-V: Can’t delete Virtual Machine with ‘Operation cannot be performed while the object in current state’

Hyper-V: Can’t delete Virtual Machine with ‘Operation cannot be performed while the object in current state’

  • Comments 9
  • Likes

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 -

image

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 -

image

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:

  1. Connect to your Hyper-V Server
  2. Open Windows Explorer
  3. 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)
  4. 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 - image
  5. Right-click on the XML file with the same GUID, and select delete
  6. Close Windows Explorer
  7. Open Hyper-V MMC console
  8. 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.

image 

To delete it, simply right-click and select delete -

image

Summary

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!)

image

Enjoy!

-Chris



Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Wondering , why there is no comment here. Yes , it worked for me :) Thanks Chris for sharing

  • Worked like magic!  Thanks!

  • restart VMM service helped me

  • Wow,Works !!!! Very help Full

  • Thank you for your article. Helped a stack.

  • Thanks a ton, worked like a champ

  • Thank you!!! You are the one that I was looking for..

  • Worked for me without restarting Hyper-V (very important). Thank you, Zbysek
    PS One suggestion: please correct the spelling of the article name/head. It will make easier for others to find. Thank you again.

  • Thanks a ton