Solved

Scripting the shut down and startup of VM's in 2008 R2 Hyper-V

Posted on 2014-12-02
15
273 Views
Last Modified: 2014-12-03
Hello experts.  I'm looking to write a script to shut down running VM's (with verification preferably - return code or something), make a copy of the VHD file (in the same folder), restart the VM's, then copy the VHD files over to some NAS storage.  I'm comfortable with everything (using regular DOS batch files) but the scripted shutdown and startup of the VM's.  I don't know any PowerShell or VB or anything like that, so if something like that would be needed, I would need to have it called by my batch process and have it return a pass/fail somehow (for both shutdown then startup)...or have the whole thing written in PowerShell or VB or whatever.

The environment is Windows Server 2008 R2 with Hyper-V.  If it matters, one VM is also 2008 R2 and the other is Windows Server 2003 R2.

Thanks for your help!
Bob
0
Comment
Question by:breichard
  • 7
  • 6
  • 2
15 Comments
 
LVL 5

Expert Comment

by:A Karelin
Comment Utility
0
 
LVL 24

Accepted Solution

by:
VB ITS earned 500 total points
Comment Utility
This article looks like it contains the steps to do exactly what you are requesting for.

You'll just need to modify Step 4 and specify the path to your NAS - I don't see the need to create a copy of the VHD files on the host then copy it again over to the NAS.
0
 

Author Comment

by:breichard
Comment Utility
Thanks for both your comments.  There are reasons why I want a copy of the whole VHD file - I won't bore you with the whole story.  The reason for copying locally first is to get the VMs back up as quickly as possible.  I'll take a look at these, hopefully today, and get back to you.

Thanks again,
Bob
0
 
LVL 5

Expert Comment

by:A Karelin
Comment Utility
Using Windows Server Backup allows you to backup running virtual machines without interraption.
0
 

Author Comment

by:breichard
Comment Utility
Understood, but it's not going to allow me to create a ready-to-go VHD file, is it?
0
 
LVL 24

Expert Comment

by:VB ITS
Comment Utility
Have a look at this article as well breichard as it will export the VM which makes DR a piece of cake. Requires a bit more work in that you need to install the Hyper-V Management Library tools but I'd personally prefer importing a VM as opposed to recreating it and then attaching the VHD as in this scenario you would have to specify the RAM, vCPUs, reconfigure the NICs inside Windows, etc.
0
 

Author Comment

by:breichard
Comment Utility
VB ITS - Can you later use Import Virtual Machine from within the Hyper-V manager?  Does part of this include a full copy of the VHD file (in case didn't care to import, just wanted to use the VHD for something else)?

Thanks, I hope to be able to work on this today.
0
Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

 
LVL 24

Expert Comment

by:VB ITS
Comment Utility
Yep, it exports the entire VM configuration which you can use to import into Hyper-V Manager on another Hyper-V host if you wanted (just make sure the other host is running the same version of Windows Server). You can still pull out the VHD files from the exported VM files if you want to make a clone of a VM for testing purposes or for whatever other reason you may have.
0
 

Author Comment

by:breichard
Comment Utility
VB ITS, I decided to try the link from your first post above (first, at least).  When the powershell script is invoked, it gets an error when it tries to do the actual InitiateShutdown.  See the screenshot.  The server name and VM name are both TEST.
PS Error message
Any ideas what may be causing this?
0
 
LVL 24

Expert Comment

by:VB ITS
Comment Utility
Did you modify the PowerShell script in Step 2 at all? Did you run it as an Administrator?
0
 

Author Comment

by:breichard
Comment Utility
<slaps forehead> Ok, I feel like an idiot.  I didn't run the command prompt as an administrator.  The basics.  Thanks so much.  I'm going to do some testing before I close this out.
0
 

Author Comment

by:breichard
Comment Utility
Do you know if the PS script would return an errorlevel (or can it be modified to do so)? I would like to test to make sure it was successful before proceeding with the copy.
0
 
LVL 24

Expert Comment

by:VB ITS
Comment Utility
It's probably easier if you add in a pause between the PowerShell shutdown command and the copy command, then verify the size of the VHD file as errorlevels in PowerShell can be a bit tricky to work out.
0
 

Author Closing Comment

by:breichard
Comment Utility
This is exactly what I needed.  Thanks VB ITS.
Bob
0
 
LVL 24

Expert Comment

by:VB ITS
Comment Utility
Good to hear you got it all working. Glad I was of help.
0

Featured Post

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Join & Write a Comment

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now