Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-12-02
15
Medium Priority
?
315 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
ID: 40477889
0
 
LVL 24

Accepted Solution

by:
VB ITS earned 2000 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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

971 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