Script for Rebooting all VMware Images on ESX

Posted on 2:24 PM by Bharathvn

Script for Rebooting All Running Virtual Machines

This is very handy if you have installed updates or anything else and want to delay the reboot till later.

#!/bin/bash
vmwarelist=`vmware-cmd -l`
vmwarelist=`echo $vmwarelist | sed -e 's/ /*/g'`
vmwarelist=`echo $vmwarelist | sed -e 's/.vmx/.vmx /g'`
for vm in $vmwarelist
do
vm=`echo $vm | sed -e 's/*/ /g'`
vm=`echo $vm | sed -e 's/ \//*/g'`
if [ `vmware-cmd "$vm" getstate | sed -e 's/getstate() = //'` = "on" ]
then
echo Found $vm that is on, Rebooting $vm
vmware-cmd "$vm" reset trysoft
fi
done