«

»

Print this Post

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:

 

 

About the author

Robert Borges

About Robert...

I have been in the IT industry since 1993 focusing mainly in networking. Though I got an early start as an amateur computer enthusiast, and wrote my first database app at age 12, I started my professional career working in the MIS department of one of the largest liquor distributors in the northeast. I started out there as a systems operator on the company’s two mainframe systems. From there I moved into PC support, and help design and implement the company’s first client-server network… This was back in the days of Win NT 3.51. I also worked on my first migration to NT 4.0 back then.

From there I went on to work with Novell 3.x and 4.x along with Windows domains and active directory environments. Working my way up from technician, to specialist, to administrator, and eventually all the way up to Sr. Engineer. I spent many years working for consulting firms, 9 of which I owned and operated my own firm.
Over the years, I have worked with (at an expert level) various versions of: Windows client and server operating systems (including Windows 7 and Windows Server 2008 R2);various virtualization technologies (Hyper-V, Virtual Server, Virtual PC, VMware, etc…); MS-SQL server 6.5- 2008 R2; Exchange 4-2010, and much more.

I am now Director of Information Systems at Bay State Integrated Technology focusing on cloud computing and IT service, with expertise in: IT Infrastructure & Architecture, IT Security, and Cloud Computing platforms & technologies (SaaS, PaaS, and IaaS).

I am in a constant state of learning about new products, and new versions of products. Many of which we end up implementing in lab environments and sometimes for our clients. I have a pretty broad range of expertise and experience. It is my goal to share some of this experience on this blog to help enrich the IT community.

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

Leave a Reply