WMware ESXI – suspend all guests

I have an VMware ESXI 5 which I used for testing things, but I don’t want it to run all the time, and using the vSphere Client to stop all the VM’s and then stop the ESXI server is a bit too much effort.

So I figured out how to do it from the commandline using ‘vim-cmd’.


VMS=`vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`
for VM in $VMS ; do
     PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
     if [ "$PWR" == "Powered on" ] ; then
          name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d """ -f2`
          echo "Powered on: $name"
          echo "Suspending: $name"
          vim-cmd vmsvc/power.suspend $VM > /dev/null &

while true ; do
     for VM in $VMS ; do
          PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
          if [ "$PWR" == "Powered on" ] ; then
          echo "Waiting..."
     if [ $RUNNING -eq 0 ] ; then
          echo "Gone..."
     sleep 1
echo "Now we suspend the Host..."
vim-cmd hostsvc/standby_mode_enter

This is working just fine, until one discovers the there is no where to store files on the ESXI servers file system without having to restore them after a reboot.

A bit of googing gave me an answer, create a directory in one of the datastores and save it there.

Like in ‘/vmfs/volumes/datastore1/scripts/’, where it will stay after a reboot.

Now to wake the host again, requires that one enable wake-on-lan (wake on PCI and PCIe normally should do it), and then use the wakelan / wol utility;

# wol <mac addr>

This it’s possible to hide ones noisy computers somewhere far far away.

7 Comments on “WMware ESXI – suspend all guests”

  1. andy says:

    Thank you, very nice :-)! Full of nice ideas, God bless ya man :o)..


  2. Russ says:

    Very cool, I have my fileserver attached to an UPS and can try to mod this to shutdown my ESXi hosts as well.


  3. dex says:

    exactly what I needed to shut down my esxi 5.5 with an UPS


  4. […] detected a power event.  Luckily, it wasn’t too difficult and I was able to find this awesome script to handle the ESX side.  Here is the […]


  5. X3STeNliTE says:

    Thank you this’s helpful.


  6. Alex says:

    Nice work! but i use command /bin/poweroff in esxi 5.5
    and may be i help some one.
    How connect to ssh from windows and run command
    download plink and run command
    plink.exe -ssh <username> -pw password /vmfs/volumes/5370dd8b-284e8baf-31ab-002421a85c91/scripts/suspend.sh


  7. Jack says:

    This may not work if you have VMs with Descriptions with multiple lines, as the descriptions interfere with the detection. Fixed by replacing the grep on the first vim-cmd with ‘grep “^[0-9]”‘ which finds numerical values on the first character of a line. Should work unless you have a number on the first character of a description line.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.