Powering off All Guests and Entering Maintenance Mode with VMWare PowerCli

We have a smaller, non-production cluster in our office that is, sadly attached to a Windows Storage server. And, given certain security requirements, we have to keep up to date (within 30 days) of Microsoft patches.

Yep, reboots on the entire VMFS.

There’s no -Evacuate switch on Set-VMHost to save us here.

This script will turn off all the VM guests in the set of VMHosts by trying the following in order:

  • Gracefully trying to shut down the guests – Shutdown-VMGuest
  • Forcefully shutting them down Stop-VM -Kill
  • Really forcefully trying to shut down via killing the PID on the ESXi host using esxcli.

It will then enter the VM Hosts in maintenance mode.

After you prompt it, it will take the hosts out of maintenance mode then try the following:

  • Bring the guets back online
  • Try to bring them up again, excerpt this time answering questions regarding “Did you copy this VM?” (I found sometimes this was an issue when completely shutting down the storage)

The Script

Leave a Reply

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