Skip Ribbon Commands
Skip to main content

Ondrej Sevecek's English Pages

:

Engineering and troubleshooting by Directory Master!
MCM: Directory

Quick Launch

Ondrej Sevecek's English Pages > Posts > How to import virtual machine into Hyper-V using WMI on Windows 2008 and Windows 2012
July 30
How to import virtual machine into Hyper-V using WMI on Windows 2008 and Windows 2012

You can find some examples on how to import an exported virtual machine to Windows 2008/R2 Hyper-V, but I was not able to find anything about importing machines into Windows 2012 Hyper-V. So here goes a brief summary of my findings:

Machines exported from Windows 2008/R2 Hyper-V

If you export a virtual machine from Windows 2008/R2 Hyper-V, it differs a bit from the newer export format of Windows 2012. The main difference is in the export file format. Windows 2008 export VMs into .EXP file.

You can import the EXP file based VMs into other Windows 2008/R2 Hyper-V or the newer Windows 2012 systems. You can use the following WMI classes and methods of the (now deprecated) virtualization WMI namespace:

WMI namespace: root\virtualization
class: Msvm_VirtualSystemManagementService
methods: GetVirtualSystemImportSettingData() and ImportVirtualSystemEx()

If the exported machines comes in the form of EXP file, you can still import it into both Windows 2008/R2 and Windows 2012 with the mentioned API.

Machines exported from Windows 2012 Hyper-V

Machines exported from Windows 2012 go into .XML format. Actually, it is no export format. It is just the virtual machine itself. Windows 2012 Hyper-V can attach VMs regardless whether they were really exported or just detached from a Hyper-V host. Which is really nice feature as the older method required dumb exports that were often unnecessary or even impossible to do in cases of OS failures or storage reconfigurations.

There is one difference though. If you want to import/attach such a virtual machine from the new XML format, you must go for the newer v2 virtualization namespace and use some new methods:

WMI namespace: root\virtualization\v2
class: Msvm_VirtualSystemManagementService
methods: ImportSystemDefinition() and RealizePlannedSystem()

 

Comments

Re: How to import virtual machine into Hyper-V using WMI on Windows 2008 and Windows 2012

when using the v2 namespace on Windows 2012, usually, you must also fix vhd paths in the Msvm_PlannedComputerSystem object. The paths point to original VHD paths as they were before the system has been exported from the original Hyper-V host (obtain the planned paths from Msvm_StorageAllocationSettingData)
 on 31/07/2013 15:24

Re: How to import virtual machine into Hyper-V using WMI on Windows 2008 and Windows 2012

also note that if you need to elaborate and test, you sometimes must delete pending Msvm_PlannedComputerSystem instances that you are not able to completelly import/finish.

To delete all Msvm_PlannedComputerSystem instances without trying to complete their import with the RealizePlannedSystem, you can use the following code snippet:

$vmms = Get-WmiObject MSVM_VirtualSystemManagementService -namespace "root\virtualization\v2"
(gwmi  Msvm_PlannedComputerSystem -names root\virtualization\v2) | % { $vmms.DestroySystem($_) }
 on 07/08/2013 17:25

Fixing VHDX paths in Msvm_PlannedComputerSystem object

How do I fix the paths using PowerShell, I fixed the SwapFileDataRoot and SnapshotDataRoot but that also gives me errors in the configuration file
 on 17/07/2018 17:07

Add Comment

Sorry comments are disable due to the constant load of spam *


This simple antispam field seems to work well. Just put here the number.

Title


You do not need to provide any value this column. It will automatically fill with the name of the article itself.

Author *


Body *


Attachments