Skip to content

Instantly share code, notes, and snippets.

@danpritts
Last active February 16, 2021 19:07
Show Gist options
  • Save danpritts/7a2e62c20940c3eed0180a705c7fc1ac to your computer and use it in GitHub Desktop.
Save danpritts/7a2e62c20940c3eed0180a705c7fc1ac to your computer and use it in GitHub Desktop.
"ps" or "vps" command to show running vms in vmware esxi shell
#!/bin/sh
echo "ID STATE NAME"
for vm in `vim-cmd vmsvc/getallvms | awk '{ print $1 }' | grep -v Vmid`;
do
echo -ne "${vm}\t"
vim-cmd vmsvc/get.summary ${vm} | egrep 'name = |powerState ' | sed 's/[,"]//g; s/poweredOn/ON/; s/poweredOff/OFF/ ;s/suspended/SUSP/' | awk 1 ORS=' ' | awk '{ print $3, "\t", $6}'
done
-----
Many useful functions are available from esxcli and vim-cmd in the esxi shell, but i was unable to find a way to generate
a concise list of registered VMs and their power state, so I did this.
getting formatting working properly was a little tricky due to the limitations of the esxi
shell busybox environment.
awk ORS=' ' was handy, credit to https://stackoverflow.com/a/14853319/908796
Sample output (slightly massaged to show up properly in the gist viewer)
[root@esxi01:~] vps
ID STATE NAME
19 SUSP vm1
21 ON vm2
22 OFF vm3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment