How to Export Hyper-V Virtual Machines
With Windows 8, more IT pros will likely be taking advantage of client Hyper-V. One task you’ll undoubtedly have to deal with is the need to create and manage backups of your virtual machines. There are a number of Hyper-V backup utilities on the market — some of them are even free — but you might be able to get by with simply exporting a virtual machine. (If you need to learn more, please refer to my article series on Windows 8 client Hyper-V, beginning with Client Hyper-V Installation and Configuration.)
When you export a virtual machine, you get the configuration file, a copy of the VHD, and any snapshots. What is attractive about this feature is that you can move the virtual machine anywhere else or even reimport it in the event of data loss or if you rebuild a system. Before you can export a virtual machine, however, it must be shut down.
Using Hyper-V Manager to Export a Virtual Machine
There are two ways to export a virtual machine. In the Hyper-V Manager, you can select a virtual machine, then right-click and choose Export from the context menu, as seen below in Figure 1.
Next, you will be prompted for a folder path as in Figure 2.
Click Export to begin. However, there’s one major “gotcha” — you can’t have a previously exported version in the same location. If you do, you will get an error like in Figure 3.
You can delete or move the existing files and repeat. Be aware that this export will need as much space as the existing VHDs and snapshots, and it might take a while to finish. Another option is to specify another path. If the folder doesn’t exist, it will be created. This would let you create date-named folders as seen below in Figure 4.
However you choose to do it, the virtual machine will be a top-level folder as you can see in Figure 5.
It is also possible to select a number of virtual machines in Hyper-V Manager and export to the same top-level directory. Remember, the virtual machine must be turned off. Each virtual machine will get its own folder structure under the specified path.
Using PowerShell to Export a Virtual Machine
Another approach is to use PowerShell to export the virtual machine (assuming you are running Windows 8 or Windows Server 2012 and have Hyper-V installed). In the Hyper-V module, you can use the Export-VM cmdlet. You can export a VM by its name.
PS C:\> export-vm "test rig" -Path E:\Exports Or as a virtual machine. PS C:\> get-vm "test rig" | export-vm -Path E:\Exports
The same rules apply: You can’t have an existing export with the same name in the target path. This makes it easy to get a number of virtual machines and export them all at once.
PS C:\> get-vm "test*" | export-vm -path E:\Exports\2012_10_04
The cmdlet won’t write anything to the pipeline unless you use –Passthru. Also be aware that Export-VM does NOT support –Whatif or –Confirm, although you could wrap this up in a function and add your own –Whatif as well as better error handling for things like existing files.
Because the export can take a long time, you can use the cmdlet’s –AsJob parameter.
PS C:\> get-vm jdh* | export-vm -Path E:\Exports\2012_10_04 -AsJob Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 2 Job2 NotSt... True get-vm jdh* | ... 3 Job3 NotSt... True get-vm jdh* | ...
You get a job for every virtual machine, and you can let them run in the background while you keep working. Overall, using PowerShell is great because it means you can set up a PowerShell scheduled job or a task to perform periodic exports.
The Export feature in Hyper-V is a handy way to perform relatively fast and easy backups, especially if you export to removable drives. Yes, there are dedicated Hyper-V backup utilities, but in some situations, exporting may be all that you really need.
More in Hyper-V
How to Install Hyper-V on Windows Server Core
Mar 16, 2022 | Michael Reinders
Microsoft Says There Will Be No Hyper-V Server 2022 Free Edition
Dec 13, 2021 | Michael Reinders
How to Stop an Unresponsive Hyper-V Virtual Machine
Jun 29, 2021 | Russell Smith
How to Enable Nested Virtualization in Hyper-V
Jun 28, 2021 | Russell Smith
Disaster Recovery with Azure Backup for SQL Server VMs
May 28, 2019 | Michael Otey
Leveraging Virtualization for Improved Availability and Disaster Recovery
Apr 29, 2019 | Michael Otey
Most popular on petri