Export a Running Virtual Machine Using PowerShell

Exporting a Hyper-V VM (virtual machine) creates a full copy of that VM. This can be used as an easy way to create an ad-hoc backup or an archive. An export can also contain all of the existing checkpoints that exist, so it is a really helpful tool during deployments, migrations, and upgrades.

In my previous post, Importing & Exporting Hyper-V VMs in Windows Server 2012 R2, I explain how to import and export a Hyper-V VM using the Hyper-V Manager GUI interface. Today I will show you how to export a VM (whether it is running or stopped) using PowerShell. In my example, I will be exporting a VM from a Hyper-V host running Windows Server 2012 R2. In this process we’ll be creating a variable and using it to hold the value of the export path. I know this is doing things the hard way, but I’m doing this for all of you who may want to script and reuse this method in the future.

 

Export a Specific VM from PowerShell

  1. From your Hyper-V host, run PowerShell as an administrator.
  2. Type the command: GET-VM
    This will display all the VMs running on the current host.
  3. Type: $ExportPath = “D:\Exports”
    Replace D:\Exports with the path you wish to use to store your exports. Make sure you have adequate disk space as exports can be quite large.
  4. Type: Export-VM -Name “Lab Test 3” -Path $ExportPath
    Hyper-V will now start exporting your VM. Check Hyper-V Manager to see the progress of your export.

While the export is processing, the PowerShell prompt will not continue to the next line. You’ll just see the blinking cursor at the end of the line you just typed. It is not hung… it will continue once the export is completed.

 

 

Export All Running VMs from PowerShell

  1. From your Hyper-V host, run PowerShell as an administrator.
  2. Type the command: GET-VM | where {$_.state -eq ‘running’} | Export-VM -Path $ExportPath
    Hyper-V will now start exporting your VM. Check Hyper-V Manager to see the progress of your export.

While the export is processing, the PowerShell prompt will not continue to the next line. You’ll just see the blinking cursor at the end of the line you just typed. It is not hung… it will continue once the export is completed.

Related Posts:

 

 

Permanent link to this article: https://www.robertborges.us/2014/07/virtualization/export-a-running-virtual-machine-using-powershell/

1 comments

    • Support on March 1, 2016 at 9:42 am
    • Reply

    How safe is this to do when they are running? Will anything be missed if not shutdown?

Leave a Reply