Recover Corrupt Hyper-V Virtual Machine

Hi All,

I am writing this article because I just recently spent a few hours figuring out how to recover a Server Farm for a development lab I have been working on in Hyper-V.

The Scenario

You have a virtual machine(s) that you have been working on, however for some reason when you start Hyper-V and you connect to your virtual machine, you receive an error such as: "Cannot connect to virtual machine because of x".  You check your logs and you discover that something is corrupt.  In my case, my snapshot files had become corrupted.  This can happen for a plethora of reasons, but the case is that it has happened. 

So what do you do?

First, turn off your Hyper-V Service and then turn it back on and try connecting again, it could be that you attached a new drive and was not picked up on service start up.

If you clicked delete on the VM already and received the "Catastrophic error" and now your VM is just hanging out, that's OK, we will address that.  If you haven't done that, that's ok too.


1.  Remove the Virtual Machine and all remnants of it from Hyper-V.

   1a.  Stop The Hyper-V Service from the Hyper-V Console on the server hosting your machine.

   1b.  Navigate to: C:\ProgramData\Microsoft\Windows\Hyper-V

          I.  You will need to select show hidden folders and give yourself administrator permissions over that folder.

   1c.  Delete only the files associated with the virtual machine.

         I.  Navigate to Virtual Machines and open each one until you find the one with tag <name type="string">YOUR NAME</name> should be near the bottom

              ia.  The file name of this .xml is that machine's GUID.

        ii.  Delete That machine and its associated (same file name) in the folder Locks.

        iii.  Repeat this for the directory Virtual Machines Cache

       iv.  Navigate to Snapshots

             iva.  Open each file and search for the GUID of your virtual machine.

             ivb.  Note the name of each of the .xml files which you find the GUID of your virtual machine in.

             ivc.  Delete all of those .xml files

            ivd.  Delete the maching file names in the folder Locks within that same Snapshots directory

     v.  Repeate iv except with Snapshots Cache.

  1d.  Start the Hyper-V Service on your server again.


2.  Restore Your Virtual Machine

This can go different ways depending on your scenario. 

1.  Virtual Machine Configuration was corrupted.

   1a.  Delete your virtual machine .xml file.

   1b.  Create a new virtual machine and point to the latest .avhdx file in accordance to the snapshot you wish to utilize from your machine.

   1c.  Point your snapshots directory to the current snapshots directory.

2.  Snapshots Configuration was corrupted

   2a.  Delete Snapshots .xml files

   2b.  Import your virtual machine as a restore pointing the hard drive to the .avhdx file in accordance to the snapshot you wish to utilize.

   2c.  Point snapshots to the folder you wish to use.

3.  You had a back up copy prior to corruption

  3a.  Delete old Directory and copy back up to this location.

  3b.  Import Virtual Machine and do it in place pointing to your newly copied over back up.


There are probably some other scenarios to consider, but those are some of the primary ones I have run into.


Hope that helps!


Comments (2)
  1. electrocreative says:

    Thanks a ton, thank you for capturing the correct and thorough way to do this, many people incorrectly believe it is simply a matter of deleting the xml and vhd files for the VM.

  2. Johan says:

    Perfect, worked very well. Helped me clean up my list of Virtual Machines which had some machines that didn't work any more.

Comments are closed.

Skip to main content