Last active
April 23, 2018 14:35
-
-
Save khorsmann/de5c1818e38b0cdc2d321dec6876d87e to your computer and use it in GitHub Desktop.
VMWare ESX 6.5 check VM powerstate on CLI
This file contains 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 | |
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