, , , ,

Hyper-V 3: Import and Export VMs with PowerShell

1–2 minutes
5 comments on Hyper-V 3: Import and Export VMs with PowerShell

Hyper-V-Powershell02

Aidan Finn (Virtual Machine MVP) just made a blog post about Hyper-V & PowerShell in Windows Server 8 and how you can enable Hyper-V via PowerShell in Windows Server 8. So this gave me the idea about doing a little more with PowerShell and Hyper-V 3.

I already did a blog post about how you can attach multiple VHDs to a SCSI Controller with PowerShell in Windows Server 8. In this post I will show how easy you can export and import a lot of Virtual Machines.

First you can run a Get-VM Test*, to check which VMs you will export.


Get-VM Test*

Now you can export the Virtual Machines


Get-VM Test* | Export-VM -Path "C:\VMs"

Now I removed the Virtual Machines in Hyper-V with Powershell (You could also add the -confirm parameter so you don’t have to press “y” for each VM.


Get-VM Test* | Remove-VM

And now you can import the Virtual Machines again


Get-Childitem "C:\VMs" -Recurse *.xml | Import-VM

Hyper-V-Powershell01

I will post more about PowerShell in Windows 8 and Windows Server 8 (Hyper-V 3) in the next upcommig weeks. If you want know more about what new Hyper-V features and improvments are coming in Windows Server 8, you can read the following blog post: “Hyper-V: Version 3 kills them all”

 

5 responses

  1. John Avatar

    Can you post a script for exporting and importing the configuration of a VM only?
    So something as the below website, but for Win8/2012 instead of Win2K8R2?
    http://social.technet.microsoft.com/wiki/contents/articles/1350.hyper-v-export-vm-config-only-using-powershell-en-us.aspx

    The script in the above link does unfortunately not work for Win8

  2. kamal thakur Avatar

    Hi Sir,

    I am looking for the sricpt which take the backups for live all Hyper-v Host in zip format. Please guide me.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.