Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts

Search

Archives

Turn virtual machines on and off from a script (Hyper-V)

Post image for Turn virtual machines on and off from a script (Hyper-V)

by Steve Wiseman on July 18, 2014 · 3 comments

in Hyper-V,Scripts


.

I got a question from Andrea this week:

“Hi Steve,

We have some VMs under HyperV that are used for training during the day and we would like to setup a vbscript that could be called from windows scheduler that could start them up in the morning, and shut them down at the end of the day. Is this possible?”

Very good question. Thankfully Microsoft has put Hyper-V into WMI, making it quite simple to do this.

I have written a script you can call from the command line this:

c:\windows\system32\cscript.exe HManage.vbs [name] [option]

The name is the name of your virtual machine

The three options are:

start – start the VM

stop – stop the VM

forcestop – Force a shutdown of the VM (Could lose data)

You can download it from here:

HManage.dat

You will need to rename it to .vbs after downloading.

Keep in mind that this needs to be run on the actual Hyper-V Server to work.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 3 comments… read them below or add one }

1 Mark July 18, 2014 at 11:29 am

Thanks for the script steve. Been wanting to do this with a test vm for a while, and have not had time to look – thanks for the time saver.

2 Jessie W July 18, 2014 at 11:41 am

Steve,

Is there a way to do this with VMWare? Specifically ESX

3 Steve Wiseman July 18, 2014 at 11:42 am

Hello Jessie,

I am not saying it is impossible, but it is much more complicated. The reason is you can’t run VBScript right on the ESX server (It is not Windows based). There might be some hooks in the VMWare client once you have it installed, but I have not tried that yet.

Leave a Comment

Category Links - Windows Forum - Exchange Forum