Monday, June 3, 2013

Export and Import a with Powershell

This has now been added to pshvm.codeplex.com a free powershell hyper-v manager project.

To Export
Create C:\export ( it creates the server name folder for you)
in powershell type  export-vm –Name Test1 –Path C:\export\test1 be patient this may take a while if your VHDx file is fixed and rather large.

Now you can browse to C:\export\test1 and you will see your exported VM structure.

To Import exactly as it was exported on the vhost with the same VMID
The original VM has to be deleted or this process needs to happen on a new VHOST.
This will import your server just as it was exported, this a not a copy of the original exported VM  is the THE ORIGINAL VM and will not import until you remove the old VM that was exported.

create folder under C:\virtualservers\"NEW NAME" in this case IMPORTVM
in powershell type
Import-VM -Path 'c:\export\test1\test1\Virtual Machines\EA6DD389-27A5-4929-8264-BD1B01D06B3C.XML' -VhdDestinationPath "c:\virtualservers\test1" -VirtualMachinePath "c:\virtualservers\test1" -SnapshotFilePath "c:\virtualservers\test1" -SmartPagingFilePath "c:\virtualservers\test1" -copy

To Import as a copy with a new VMID
The original VM DOES NOT have to be deleted or this process can to happen on a new vhost
This will import your server just as it was exported, this a copy of the original exported VM  the name will remain the sames as it was exported but the VMID will change. Thus if you import back onto the original VHOST you will havbe two servers named TEST1. You do weell to rename the new TEST1 ASAP. name Rename -VM TEST1 -NewName TEST3

create folder under C:\virtualservers\"NEW NAME" in this case IMPORTVM
in powershell type
Import-VM -Path 'c:\export\test1\test1\Virtual Machines\EA6DD389-27A5-4929-8264-BD1B01D06B3C.XML' -VhdDestinationPath "c:\virtualservers\test1" -VirtualMachinePath "c:\virtualservers\test1" -SnapshotFilePath "c:\virtualservers\test1" -SmartPagingFilePath "c:\virtualservers\test1" -copy -generatenewid

NOTE: you may want to run sysprep on the new copy of the server.


No comments:

Post a Comment