I am not using my server during the night so in order to save electricity I want it to turn itself off at 00:30 AM and turn it self on at 08:30 AM. When it turns itself on it also needs to power up certain VM’s. Like my Mediaserver and Deployment / VPN server. I’m using HyperV 2012R2 core. So there is no GUI to control task scheduler. Lucky for it there is a command line to do this
With SCHTASKS we control the task scheduler. We can launch certain jobs at certain times. It is the same as the GUI version we all know
BOOT THE SERVER
In order to boot your server you need to configure the bios. You can’t do this remotely. Go into your server Bios and make sure wake up on LAN is turned on at wake up time is 08:30 AM. On some bios you have to search for it but it should be there. We select wake up on lan because if I need it after 00:30 AM. I can boot it up with a WOL command
SHUTDOWN THE SERVER DAILY
I use windows remote desktop to the HyperV server. You can also do this remotely from a the command line but this is just the easy way for me to do it.
1. In server manager select the HyperV server and then right mouse click and select remote desktop connection
2. Select the command prompt and type in the following SCHTASKS /create /tn Shutdown /tr “Shutdown /s” /sc DAILY /st 00:30:00
So here we create a new task called shutdown and launch it daily at 00:30 AM. The task will launch the command shutdown /s
AUTOMATICLY BOOT UP THE VIRTUAL MACHINES
This one is easy. Go into your HyperV manager and select the VM you want to boot when the server boots.
Go to settings and select Automatic start up action. Also make sure that the automatic stop action is on save. This means that when the server shutdown the state of the machine will be save. When the server boot next time and boot up the VM it starts the server out of save mode meaning that the VM is like it never stops. So the VM does not have to boot every time on its own. Sort of like hybernation
I put in a start up delay of 5 second giving the server some time to boot all that is needed. If you have multiple VM’s you want to boot then do not boot them all at once. otherwise your server will get slow when booting. best is to put at least 30 seconds between the VM boot times
And that is it. My server will now shutdown at 00:30 AM and boot at 08:30 and when booting it will boot up the VM’s I wanted