Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created August 2, 2015 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/6c45b6d00f59c9cfc5f4 to your computer and use it in GitHub Desktop.
Save jpluimers/6c45b6d00f59c9cfc5f4 to your computer and use it in GitHub Desktop.
vmware console command to resume all VMs that are suspended
#!/bin/sh
SUSPENDED=0
VMS=`vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}'`
VMstateToProcess="Suspended"
for VM in $VMS ; do
# echo "Probing VM with id: $VM."
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | awk -F'"' '{print $2}'`
echo "VM with id $VM has power state $PWR (name = $name)."
if [ "$PWR" == "$VMstateToProcess" ] ; then
SUSPENDED=1
echo "Suspended VM with id $VM and name: $name"
echo "Resuming VM with id $VM and name: $name"
# you'd think power.suspendResume is the inverse of power.suspend, but actually power.on is:
vim-cmd vmsvc/power.on $VM > /dev/null &
fi
done
while true ; do
if [ $SUSPENDED -eq 0 ] ; then
echo "Gone..."
break
fi
SUSPENDED=0
for VM in $VMS ; do
PWR=`vim-cmd vmsvc/power.getstate $VM | grep -v "Retrieved runtime info"`
if [ "$PWR" == "$VMstateToProcess" ] ; then
name=`vim-cmd vmsvc/get.config $VM | grep -i "name =" | awk '{print $3}' | head -1 | awk -F'"' '{print $2}'`
echo "Waiting for id $VM and name: $name..."
SUSPENDED=1
fi
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment