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
- From your Hyper-V host, run PowerShell as an administrator.
- Type the command: GET-VM
This will display all the VMs running on the current host.
- 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.
- 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
- From your Hyper-V host, run PowerShell as an administrator.
- 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:
Related
Robert Borges
About Robert...
I have been in the IT industry since 1993 focusing mainly on 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 when I worked on my first migration to Windows NT 4.0 server.
From there I went on to work with Novell 3.x and 4.x along with Windows domains and Microsft's brand new Active Directory. Working my way up from technician to specialist, to an administrator, and eventually all the way up to Sr. Engineer. I spent many years working for MSPs/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 11 and Windows Server 2019); various virtualization technologies (Hyper-V, VMware, etc.); MS-SQL server 6.5- 2014 R2; Exchange 4-2019, and much more. Over the years I have built a lot of experience around the Microsoft Azure and Microsoft 365 cloud environments.
I am now CTO at Infused Innovations where our team is focusing on helping clients build a Secure Intelligent Workplace through InfoSec (Zero Trusts Framework), Modern Workplace, and Business Intelligence.
I have been heavily involved in the IT user group community, including serving as president of the board of Boston User Groups, Inc., and president of IT-Pro User Group. In 2017/2018 Microsoft awarded me the Microsoft MVP (Most Valuable Professional) Award, with a focus of Microsoft Azure cloud, for my efforts in the IT community.
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 very 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: https://www.robertborges.us/2014/07/virtualization/export-a-running-virtual-machine-using-powershell/
1 comments
How safe is this to do when they are running? Will anything be missed if not shutdown?