Solved

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

Posted on 2014-12-02
15
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 5

Expert Comment

by:A Karelin
ID: 40477889
0
 
LVL 24

Accepted Solution

by:
VB ITS earned 500 total points
ID: 40478111
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
ID: 40478320
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 5

Expert Comment

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

Author Comment

by:breichard
ID: 40478364
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
ID: 40478375
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
ID: 40478462
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
 
LVL 24

Expert Comment

by:VB ITS
ID: 40478472
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
ID: 40479189
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
ID: 40479512
Did you modify the PowerShell script in Step 2 at all? Did you run it as an Administrator?
0
 

Author Comment

by:breichard
ID: 40479527
<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
ID: 40479532
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
ID: 40479673
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
ID: 40480035
This is exactly what I needed.  Thanks VB ITS.
Bob
0
 
LVL 24

Expert Comment

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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

710 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