Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.