• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1460
  • Last Modified:

Import VM to Hyper-V using script?

I have a virtual domain named "labdomain" which I use for software testing. I have various Windows versions which I test software against. After testing I delete the VM's and when needed I import them again and start installing the software and test the functionality.
What I really need is a script to import the VM's. They are located on a separate hdd and I always import the same set of VM's. I always use the options "Move or restore .." and "Duplicate all files ..". This manual import is cumbersome, slow and prone to errors. E.g. forgetting to check the "Duplicate all files.." option.

I found a Powershell script suite made for Hyper-V which I tried, it is way too complicated to me. Never got it to work and since I have no clue how it works I am afraid I might break something.

Anyone here got ideas how to solve this?

I use the Hyper-V in Windows 2008 R2.
1 Solution
BillSystems AdministratorCommented:
One primitive scripting option would be to:
1- Stop the VM
2- Copy over the .VHD
3- Start the VM
In other words there's no real reason to delete and re-import the VM if it hasn't fundamentally changed:  NIC IP address, etc.

I did find some other resources however to consider.  The following article looks helpful:

Import-Module Hyper-V
$VMs = Get-VM
foreach($VM in VMs)
  Shutdown-VM -VM $VM.VMElementName
  Export-VM -VM $VM.VMElementName -Path <your export path>
  Start-VM -VM $VM.VMElementName
  Import-VM -Path <your export path> -Server <other hyper-v server>

jerraAuthor Commented:
Excellent, the copying of the .vhd works for me!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now