Shutdown Your HomeLab With PowerCLI

Introduction

If you run a large home-lab like I do, shutting it down in an emergency can be a slow process, especially if you are panicking about your UPS staying up long enough.  You  DO have a UPS don’t you.!?

I had written a PowerCLI script for myself that was custom to my specific lab.  I have since made it more generic so that everyone can use it if they wanted to.  The script does rely on one specific criteria for your home-lab though.

 

Home-Lab Layout

vc-foldersWithin the vCenter VMs and Templates view, you can organise your VMs into folders to help separate them into logical groups.  This has no bearing on the VMs themselves, its purely for your information.

As you can see by this image, I have a folder called Critical that I use to hold my important VMs.  These are…

  • live-dc : The DHCP and DNS server for my home network,
  • svr-dc : The domain controller, as well as DHCP and DNS for my private lab network,
  • svr-sql : The Microsoft SQL server for my private network.  This holds all the databases for my lab,
  • svr-vc : The VMware virtual centre server for my home-lab.

This Critical folder is important in my script, as it controls which VMs are not shut down immediately, but must wait until the end and be shut down in a specific order.

 

The Script

The script can be downloaded below, make sure you read though it fully and understand how it works.  I am not responsible for anything going wrong.!

At the top of the script, you will need to change the settings to match your own home-lab.

[string]$vCenter_Server                    = "svr-vc"
[string]$vCenter_Server_UserName           = "administrator"
[string]$vCenter_Server_Password           = "********"

[string]$Known_ESX_Host                    = "esx1"
[string]$Known_ESX_Host_UserName           = "root"
[string]$Known_ESX_Host_Password           = "********"

[string]$Critical_Folder                   = "Critical"
[string[]]$Critical_Servers_Shutdown_Order = ("svr-vc", "svr-sql", "svr-dc", "live-dc")

[int]$Shutdown_TimeOut = 180 # Seconds

Lines:

  1. The name of your virtual centre server
  2. The username you use to connect to your virtual centre server
  3. The password for the above username
  4. .
  5. The name of one of your ESXi hosts.  This is explained below
  6. The username of the root account of for the above host
  7. The password for the root account
  8. .
  9. The critical folder mentioned above (not case sensitive)
  10. The servers in your critical folder, in the order they should be shut down in
  11. .
  12. How long to wait for a clean shut down before killing power to a virtual machine

 

Specific ESXi Host Name

The reason for a specific host name in the script, is so that when you come to power on your home-lab, you will know exactly which host will hold your critical VMs.  The script will migrate all powered off VMs as well as your critical ones to this host before powering everything down.  If you have a number of hosts it’s helpful if you don’t need to check each one for your domain controller is virtual centre server.

 

Download

Download the script from the link below, and again, make sure you test it before putting it live.!

ShutdownEntireHomeLab.ps1download-file

Leave a Reply

Your email address will not be published. Required fields are marked *