Importing VM´s with PowerShell into Win8 Hyper-V 3.0

I am working on setting up my lab environment for the M50273 Design course that I am going to teach next week.

The import process is a bit heavy without powershell, cause it is 18 VMs that has to be imported. In a MOC (Microsoft Official Course) the lab setup consists of several VM´s that have base vhd disks and then several tiers of differential disks that need to be connected before import, in every directory there is a .bat file that creates the symlinks, I decided to keep them but run them in a script.

And here you can see the result of running the .bat file

The setup guide for the course says that I should install a Windows 2008 R2 host and then import the VM´s but i want to use Win8 instead, this to be able to run the built-in hyper-v cmdlets and also test if I could run the course VM´s on it.

I did not have this problem (Matthew Dowst) when importing my VM´s to the host but another networking issue occured, when checking the VM settings as you can see in the screen dump that the virtual network adapter is there but not working correctly, a little powershell again helps 😛

And this powershell command that takes the network adapter on the vm and connects it to the Internal switch :

Get-VM *HOU-DPM-E* | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName Internal

So then it looks like this in VM settings:

So to automate the import process I created a small script that looks in a directory for VM´s in folders to import, then starts each .bat script to create the symlinks and imports the machine and lastly renames it (cause in the import process it is named REARMEDxxx) and connects the vm to the right network

As you can see, in this script i have not created a function or fancy parameters, that might come in a version 0.2.

# Import VMs for Course
# Niklas Akerlund / RTS 2012-04-04

$VMs = Get-Item -Path "E:\Program Files\Microsoft Learning\50273\Drives\*" | Select-Object Name,FullName

foreach ($VM in $VMs){
    if(Get-VM $VM.Name -ErrorAction SilentlyContinue ){
        Write-Host $VM.Name "Already imported"
        # Create Symlinks
        $symbat = (Get-Item ($VM.FullName + "\*.bat")).FullName
        & $symbat

        $expfile = (Get-Item ($VM.FullName + "\Virtual Machines\*.exp")).FullName
        Import-VM -Path $expfile 

        Get-VM REA* | Rename-VM -NewName $VM.Name
        Get-VM $VM.Name | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName Internal

It looks something like this when running

And when it is done I have all my 18 VMs imported and with the right network connected:



It create only one symlinks 🙁 and do not import my VMs. Could you help me?

Leave a comment


email* (not published)