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.
Read the Best Personal and Business Tech without Ads
Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.
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.