Import VM to Hyper-V using script?

Posted on 2011-05-08
Last Modified: 2012-05-11
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.
Question by:jerra
    LVL 8

    Accepted Solution

    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>


    Author Closing Comment

    Excellent, the copying of the .vhd works for me!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Introduction In one of my previous articles (, I explained how to create a native Windows 2012 Cluster.  The metho…
    Nowadays, Virtual Machines are used equally by small and large scale organizations. However the issue is that VMDK files are also prone to corruption. So, in this article we are looking at how to recover VMDK files from hard disk of host operating s…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now