You can import and export VMs using Hyper-V Manager or System Center Virtual Machine Manager, but it's just as...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
easy to use PowerShell commands. Microsoft offers the necessary commands to perform both import and export operations for VMs running on Hyper-V.
The Export-VM PowerShell cmdlet is available on any computer on which the Hyper-V role is installed, but you can also install Hyper-V PowerShell modules on a management server and perform necessary Hyper-V operations. To export a single VM, execute the following command:
“Export-VM <VMName> -Path “<PathToExportVMFiles>”
Export-VM takes the necessary actions before exporting VM files, such as creating a folder on the path specified in the -Path variable, which creates three subfolders: Snapshots, Virtual Hard Disks and Virtual Machines. These subfolders contain VM files, such as the extensible markup language (XML) file, which contains VM configuration, VM snapshot and VHDX files. If you want to export all VMs running on the local Hyper-V host, run the Get-VM | Export-VM –Path <PathToExportVMFiles> command. If you want to export specific VMs, all you have to do is create a text file that contains VM names and then execute the PowerShell script below.
ForEach ($VMName in Get-Content "$VMFile")
Export-VM -Name $VMName -Path "E:\VMs\"
This will export only the VMs specified in the C:\Temp\VMs.txt file. All VMs will be exported under the E:\VMs folder.
It's important to note that Export-VM doesn't support a -ComputerName parameter, which you can use to export a VM on a remote Hyper-V host.
The Import-VM PowerShell cmdlet can help you import a VM. To import a VM, execute the command below:
Import-VM –Path “E:\VMs\VMGUID.XML” OR <E:\VMs\VMGUD.VMCX”
When it comes to importing a VM, the import process takes any necessary actions. For example, if the VM is already registered with Hyper-V, it deletes the existing VM with the same VM globally unique identifier and then registers the VM again. If you are importing the VM on a different Hyper-V host, the import process just proceeds with the registration of the VM because the VM doesn't already exist. Note that you shouldn't import multiple VMs using a PowerShell script as the import process also checks the VM's compatibility on the target Hyper-V host.
Tap into the PowerShell pipeline
Navigate Windows PowerShell with this guide
Dig Deeper on Microsoft Hyper-V management
Related Q&A from Nirmal Sharma
System Center Orchestrator provides Run .Net Script activity, which can be used to call PowerShell scripts, but there are limitations you should know.continue reading
By referencing various log files, like the Real-Time Log and the Historic Log, and checking the Orchestrator Runbook Audit History page, you can more...continue reading
To execute custom scripts for Azure Windows and Linux VMs to support post-deployment configurations, you'll have to download the Azure Custom Script ...continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.