Remotely Powering On and Off My Entire Home Lab

RemoteMy home lab consists of 3 PCs running Hyper-V and a HP Proliant Microserver N54L running SCVMM. I have previously blogged the lab setup in a 2-part blog posts (Part 1, Part 2). These 2 blog articles was written back in October 2012, although there are few changes in the current setup (new hardware, etc), but the overall setup is pretty much the same.

All 4 machines in my lab have been constantly running 24×7, except when we go on holidays or there’s a power outage (which doesn’t happen very often). This is largely because I just can’t be bothered to spend time start and shutdown all the physicals and virtuals every time I use the lab, not to mention I often access my lab when I’m in the office via RDP using my Surface Pro 2 with an external monitor. Because all of the computers are PC grade hardware, there are no out-of-band management cards (i.e. iLo, DRAC, etc.) on these boxes, I had no way to remotely start them when I was in the office.

In order to reduce the “carbon footprint”, and more importantly, my electricity bill, I have been wanting to automate the the start and shutdown process of the entire lab for a while. Last weekend, I finally got around to it, and accomplished it by using only Wake On LAN (WOL) and PowerShell (with PowerShell Web Access, WinRM and CredSSP).

Because one of the PCs in my lab is my main desktop (running Windows 8.1 with Hyper-V role enabled), this PC is always running. my solution is to use this desktop (called “Study”) to interact with other physical computers in the lab. I’ll now go through the steps I took to archive this goal:

1. confirm / configure Wake-On-LAN on all physical computers in the lab.

I installed a freeware called AquilaWOL on my “Study” PC, made sure I can WOL all other computers.

image

During my testing, the HP Microserver and one of the Hyper-V box (HyperV01, the one with the Intel motherboard) had no problem at all. However, the other HyperV box HyperV02, would not WOL. after some research, it seemed like a known issue with the motherboard that only be able to WOL when the computer is at sleep, not when it’s powered off. Luckily other than the on-board Marvell NIC, I also have a dual port Intel GB NIC and a single port Intel desktop GB NIC on this computer. the dual port NIC also wouldn’t work. but the desktop NIC worked 🙂

2. Installed a Windows Server 2012 R2 virtual machine on my “Study” PC.

I named this VM “JUMP01” because I intend to use this as a jump box. I connected this VM to the virtual switch  which is on the same subnet as all physical computers – so I don’t rely on switch/routers to relay WOL packets. I also need my AD environment to be available when running the script, but because I have a domain controller already running as a VM on my Study PC, no additional VM’s are required.

3. Installed and configured PowerShell Web Access on the Jump server.

So I don’t have to RDP to the jump server to run the scripts. This also enables me to power on / off the lab from any mobile devices with a browser. I have followed my previous blog post to install and configure PSWA. I also wrote a PowerShell module to resize PowerShell console size to make PSWA more user-friendly for mobile devices.

4. Developed PowerShell scripts to power on and power off the physical and virtuals.

I wrote 2 scripts: start-lab.ps1 and stop-lab.ps1. both scripts read required information from a XML file (labconfig.xml). this XML file contains all required information for my lab environment.

SNAGHTML6bd3b2

The PowerShell scripts utilise WinRM and CredSSP to interact with each physical computers (using PSSessions and Invoke-Command).

Below is a list of steps each script performs:

Start-Lab.ps1:

  1. Read XML, get information for all computers that are a member of the lab
  2. ping each lab member, send WOL magic packet if ping failed
  3. wait for 90 seconds (configurable via XML)
  4. Check OS readiness (configurable via XML)
    • Minimum up time
    • all required services are running
  5. Once the OS is ready on the Hyper-V hosts, start VMs in groups hardcoded in the script (based on my naming standard in the lab).
    • firstly start the CentOS VM configured as routers (they are configured to auto start with the host, but just in case they did not start).
    • Then start the domain controller
    • Then start all VMs hosting SQL databases (OpsMgr DB, ConfigMgr site servers, Service Manager DB, etc).
    • Then start all other VMs except OpsMgr management servers
    • Lastly, start all OpsMgr management servers (they must be started at the end so I don’t get any alerts).

Stop-Lab.ps1:

  1. Read XML, get information for all computers that are a member of the lab
  2. ping each lab member, ignore the lab member if it does not respond to ping
  3. shutdown VM’s in order (which is the reverse order as the start-lab.ps1)
  4. double check if all VM’s are completely shutdown, if not, forcibly turn them off
  5. shutdown Hyper-V servers (and non-hyper-v physicals).

Note: the WOL function in my script is taken from here: http://gallery.technet.microsoft.com/scriptcenter/Send-WOL-packet-using-0638be7b

5. Created a simple PowerShell module to execute the 2 steps I wrote.

On the jump server, I created a powershell module called “LabAdmin”, which contains 2 functions that simply execute the powershell script:

image

6. Configured port forwarding on my ADSL router to allow me to access the PSWA site from the Internet

This allows me to manage my lab even when I’m not home.

i.e. starting the lab via my mobile phone (over 4G):

image

Here are the live demos for both scripts:

Start-Lab:

Stop-Lab:

For your reference, the scripts can be downloaded HERE.

Conclusion

I live in Australia, one of the countries with the highest electricity prices. It is time for me to do something to cut down the running cost of my home lab – especially when my colleagues told me their average electricity bills are only half of mine.

Now, I can remotely start my entire lab anywhere via my mobile phone, and it only takes me a single command to shut down the lab, I won’t need to have them running 24×7. So I’m hoping my implemented this new feature in my lab, I should be able to see some noticeable reductions in my next power bill. 🙂

2 comments

  1. Excellent post. I am going to use it for my home lab. I was looking for this type of solution for a long while. Not good at PS. With your help, I will make use of the PS script and test. Thanks!!!!!!!!!!

Leave a Reply

%d bloggers like this: