Question

I have a bunch of Hyper-V virtual disks I would like to import. My OS is Windows 8.

There are official Microsoft labs images and I can import them from the GUI by following this procedures:

  1. Select Import Virtual Machine
  2. Select the folder containing the virtual image
  3. Select the Virtual Machine
  4. Select "Register the virtual machine in-place" for the Import Type

This works perfectly, but since I have a lot of labs, I want to automate this is via a PowerShell script. The Import-VM command accepts a Path parameter which is the path to the VM's XML file. However, the XML files do not exist in my machines until the import is completed via the GUI.

I need some guidance on how I can automate the manual procedure above via PowerShell, i.e. leverage Import-VM to import from a folder path only.

This would save me a ton of time when re-creating my labs across my student's machines.

Any help is appreciated.

Was it helpful?

Solution

Figured it out. The trick was to call Import-VM and specify a path to the .exp which comes with the labs.

Import-VM -Path $expfile 

This post really helped: http://vniklas.djungeln.se/2012/04/04/importing-vm%C2%B4s-with-powershell-into-win8-hyper-v-3-0/

OTHER TIPS

Use New-VM cmdlet instead ie. New-VM –Name "VM1" –MemoryStartupBytes 1GB –VHDPath C:\vhds\yourImage.vhdx -Path C:\VMS

Run get-help New-VM -Examples or visit http://technet.microsoft.com/en-us/library/hh848537.aspx for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top