Powershell Script to Shutdown and Export Hyper-V VMs, one at a time, for Windows Server 2012 - 2016

by Stan Czerno September 8, 2012 10:13 CST

Powershell Script to Shutdown and Export Hyper-V VMs, one at a time, for Windows Server 2012.

Now that I have rebuilt my cluster using Windows Server 2012, I had to change my Export script since the new Powershell Management for Hyper-V 2012 is different from the PowerShell Management Library for Hyper-V. 

I added a Log File, which is emailed after the script finishes.

This script can be used on a Hyper-V 2012 - 2016 Cluster or Stand-Alone Hyper-V 2012 - 2016 Server.

Let me know what you think about the script and if you have a better way of doing this.

http://www.czerno.com/default.asp?inc=/html/windows/hyperv/cluster/HyperV2012_Export_VMs.asp

Tags: ,

Catergories: Windows | HyperV | Powershell

Comments (8) -

Ryan United States
September 15, 2012 13:04 CST

Perfect quick solution to get VM's off the RC install to rebuild RTM.  Now if you only had the same as an Import Smile

Thanks again!

Jeff Canada
April 3, 2013 08:18 CST

Thanks so much for sharing this. It's working very well for me to back up my VMs from Hyper-V 2012 cluster.

Aaron United States
October 17, 2013 22:27 CST

Only issue I have with this script is that it appears it doesn't truly do a guest shutdown.  Instead it powers of the VM's.

I notice this because every time the script runs and the VM comes back up, it says Windows wasn't shutdown properly.

Stan Czerno United States
October 18, 2013 08:54 CST

The script is using the "Stop-VM" PowerShell cmdlet. The script implements the "-Force" parameter to force off the VM if it takes more than five minutes to shutdown.

Try removing the "-Force" parameter from line 54 and see if it works better for you.

For more info on the "Stop-VM" cmdlet, visit this link on TechNet: technet.microsoft.com/en-us/library/hh848468.aspx

Nzer 2012R2 Switzerland
October 25, 2013 05:59 CST

Hello Stan, great script- Although I know that in 2012R2 the EXORT-VM works without shutdown I like your script but I do have Problems with the heartbeat function. It doesnt work in 2012R2. Do you already have a solution for that. Would be very nice.

Stan Czerno United States
October 25, 2013 07:13 CST

I have not yet upgraded my Lab to R2 so I have not tested the script. I will work on updating the script when I find some time to upgrade to R2.

Nzer 2012R2 Switzerland
October 26, 2013 04:16 CST

Hello Stan, I think i found a solution. I am using the german Version of 2012R2 as a host and a german 2008R2 as VMs. It seems that the Name changed. If a am replacing  "heartbeat" with "takt" everything is working as usual. Maybee it is usefull for some german os users.

Stan Czerno United States
October 26, 2013 04:30 CST

OK, good to hear. I guess "herzschlag" didn't flow right.

Comments are closed