Skip to content

Instantly share code, notes, and snippets.

@jauderho
Created August 14, 2016 22:36
Show Gist options
  • Save jauderho/4e2d771d5f3154fbd63552513d601ad3 to your computer and use it in GitHub Desktop.
Save jauderho/4e2d771d5f3154fbd63552513d601ad3 to your computer and use it in GitHub Desktop.
VMware ESX - Resume all VMs
#/bin/sh
VMS=`vim-cmd vmsvc/getallvms | grep vmx | awk '{print $1}'`
for VM in $VMS ; do
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Suspended" ] ; then
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | cut -d "\"" -f2`
echo "Suspended: $name"
echo "Resuming: $name"
vim-cmd vmsvc/power.on $VM > /dev/null &
fi
done
while true ; do
RUNNING=0
for VM in $VMS ; do PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "Suspended" ] ; then
echo "Waiting..."
RUNNING=1
fi
done
if [ $RUNNING -eq 0 ] ; then
echo "Done..."
break
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment