PowerTip: Identify Locations of Hyper-V Config Files

Summary: Use PowerShell to find the .xml files of Hyper-V virtual machines.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily find the location of my virtual machines after I reinstalled Hyper-V in Windows Server 2008 R2?

Hey, Scripting Guy! Answer The virtual machine configuration is stored in an .xml file with a GUID, and you can use Get-ChildItem to easily parse a hard drive to find the location.

To scan drive C: for all .xml files:

GET-CHILDITEM C: -recurse -include *.xml

To be more efficient, target only C:ProgramData where the data, including hidden folders, is stored:

GET-CHILDITEM C:ProgramData –recurse –include *.xml –force

If you need to manually rebuild configuration data, you can parse files for machine names and data.

Comments (4)

  1. @jrv

    Good point.   To second part is to identify content which oddly enough I didn't type in

  2. jrv says:

    Ttoal XML files in C:progrmdata  Count    : 2753

  3. jrv says:

    The files are kept in the Hyper-V folder:

    C:ProgramDataMicrosoftWindowsHyper-VVirtual Machines

    Each VM is an XML file named with a GUID.  They should be the only XML files in that folder.  The folder can be moved but usually isn't as the XML file can relocate the VM to anywhere.   All VM info for settings shown in Hyper-V Manager should be in these files.

  4. Krunch {The Commenter formerly known as K} says:

    I have been trying to solve this for days. all i needed was a comma and some regex

    gci C: -r -in *.xml |  | ?{$_.name -match "w{7,}-w{3,}-w{3,}-w{3,}-w{11,}"}

    gci C:ProgramData –r -in *.xml |  | ?{$_.name -match "w{7,}-w{3,}-w{3,}-w{3,}-w{11,}"}