Script: Emergency – Shutdown

sam.aaron/ January 5, 2011/ Daily, ESX, VMware/ 0 comments

Recently I had a vSphere 4.0 U1 environment experience a major outage. I had to bring down our entire environment consisting of 242 guests and 6 hosts. I knew that I had a bash script that I wrote for a 3.5 environment for this scenario, but due to logistical reasons it was unavailable. I had to come up with a quick solution as everyone was waiting on me.


A quick search on a site that is becoming a favorite of mine found me a solution that I could run in powercli. Alan Renouf created this script. (Thank you Alan.) After the outage, I took another look at his script and wanted to add a few other touches to it – specifically a warning screen with a way to safely stop the script before starting to shutdown VMs. Since I will be sharing this script with co-workers, I needed a way for them to stop the script if they accidentally started running it by mistake.

I am running the following revised script in PowerCLi version 4.1.

The script is available for download here (Right-Click and “Save As”).

A few words of caution: Run this script in a fresh powercli or powershell window. If connecting to vCenter, this script will contact EVERY ESX host and start shutting down ALL VMs. If you need to shut down specific VMs on an ESX server, then connect to that server individually. Or comment out LINE 58 and uncomment LINE 59 or 60 for the specific Cluster or Datacenter that you need powered off.

Print Friendly, PDF & Email
Share this Post