Q
Manage Learn to apply best practices and optimize your operations.

Execute Import-VM and Export-VM PowerShell commands in Hyper-V

Although you can use Hyper-V Manager or SCVMM to import and export VMs, it's just as easy to use a couple PowerShell commands to perform those actions.

You can import and export VMs using Hyper-V Manager or System Center Virtual Machine Manager, but it's just as...

easy to use PowerShell commands. Microsoft offers the necessary commands to perform both import and export operations for VMs running on Hyper-V.

Export-VM cmdlet

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.

$VMFile="C:\Temp\VMs.TXT"

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.

Import-VM cmdlet

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.

Next Steps

Tap into the PowerShell pipeline

Navigate Windows PowerShell with this guide

Use PowerShell to configure Hyper-V replication

This was last published in August 2017

Dig Deeper on Microsoft Hyper-V management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What are some other important considerations for using the Import-VM and Export-VM PowerShell commands?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close