Skip to content

Instantly share code, notes, and snippets.

@khorsmann
Last active April 23, 2018 14:35
Show Gist options
  • Save khorsmann/de5c1818e38b0cdc2d321dec6876d87e to your computer and use it in GitHub Desktop.
Save khorsmann/de5c1818e38b0cdc2d321dec6876d87e to your computer and use it in GitHub Desktop.
VMWare ESX 6.5 check VM powerstate on CLI
#!/bin/sh
startit() {
vmids=$@
for vmid in $vmids
do
echo -n "check $vmid powerstate: "
stat1=$(vim-cmd vmsvc/power.getstate "$vmid" | grep "off")
if [ "$stat1" == "Powered off" ]
then
echo "power on $vmid"
vim-cmd vmsvc/power.on "$vmid"
else
echo "$vmid is already on"
fi
done
}
echo "start this vmids first"
vmids=$(vim-cmd vmsvc/getallvms | egrep 'veryimportant1|anotherone|thirdone' | awk '{print $1}')
startit $vmids
echo "start all vmids"
vmids=$(vim-cmd vmsvc/getallvms | awk '{print $1}' | grep -v Vmid)
startit $vmids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment