How to Export a Hyper-V Virtual Machine using PowerShell

Hyper-V Portability

In a Hyper-V virtualization environment, a virtual machine (VM) is not a single file. It is a complex collection of configurations (XML or VMCX files), virtual hard disks (VHD/VHDX files), snapshot checkpoints (AVHDX files), and sometimes saved memory states (BIN/VSV files). If you attempt to copy a VM to a USB drive simply by copying the `.vhdx` file using File Explorer, you will lose all the hardware configurations (MAC addresses, virtual switch assignments, CPU core allocations) and any active snapshots.

To safely migrate a virtual machine to another server, or to create a reliable offline backup, you must Export the VM. The export process safely consolidates all the disparate files, merges necessary checkpoints, and packages the entire VM into a single, highly portable directory structure.

While this can be done via the Hyper-V Manager GUI, using PowerShell allows administrators to easily automate the nightly export of dozens of critical servers.

Using the Export-VM Cmdlet

To interact with the Hyper-V hypervisor, you must run PowerShell with elevated Administrator privileges.

Suppose you have a production web server named IIS-Web01, and you want to export it to a backup drive mounted at E:\VM_Backups.

The command is straightforward:

Export-VM -Name "IIS-Web01" -Path "E:\VM_Backups"

When you run this command, PowerShell creates a master folder named IIS-Web01 inside the backup directory. Inside that folder, it constructs three subfolders: Virtual Machines (containing the config files), Virtual Hard Disks (containing the VHDX), and Snapshots.

Live Export Capabilities

Historically, exporting a virtual machine required you to shut down the guest OS, resulting in unacceptable downtime for production servers. However, starting with Windows Server 2012 R2 and Windows 10, Microsoft introduced Live Export.

The Export-VM cmdlet fully supports Live Export by default. You can run the exact command above while IIS-Web01 is actively serving web traffic. Hyper-V will seamlessly utilize the Volume Shadow Copy Service (VSS) to take a live, application-consistent snapshot of the machine, export the snapshot to the backup drive, and then silently merge it, all without dropping a single TCP connection.

Exporting Multiple VMs Simultaneously

The true power of PowerShell lies in the pipeline. If you have a Hyper-V host running 15 development virtual machines, and you want to export all of them to an external SAN before performing a host OS upgrade, you do not need to type the command 15 times.

You can use the Get-VM cmdlet to grab all the machines, filter out the production ones, and pipe the rest into the export command.

Get-VM -Name "DEV-*" | Export-VM -Path "E:\VM_Backups\DevArchive"

This single line of code will iterate through every virtual machine on the host whose name begins with “DEV-” and export them sequentially to the SAN, providing a completely automated disaster recovery snapshot of your entire development environment.

Importing the VM

Once the export is complete, the resulting directory is completely hardware-agnostic. You can copy that folder to a USB drive, walk it over to a brand new Windows Server 2022 physical host, open PowerShell, and run the Import-VM cmdlet against the exported configuration file to instantly register the VM on the new server, retaining its original MAC address and configuration state perfectly.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.