Created
August 14, 2016 22:34
-
-
Save jauderho/aa81cab27c8030ae8b5a68ab08ac70f5 to your computer and use it in GitHub Desktop.
VMware ESX - Suspend all VMs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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" == "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 & | |
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" == "Powered on" ] ; then | |
echo "Waiting... $VM" | |
RUNNING=1 | |
fi | |
done | |
if [ $RUNNING -eq 0 ] ; then | |
echo "All VMs suspended..." | |
break | |
fi | |
sleep 1 | |
done | |
#echo "Now put host in maintenance mode ..." | |
#vim-cmd hostsvc/maintenance_mode_enter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment