Whilst I’m aware that it’s simple enough to type
vim-cmd vmsvc/getallvms from the cli in vSphere/ESXi, having a program spawning another program is a bit of a pain, especially having to parse the results(vim-cmd output is a bit of a mess). To programmatically handle this requires a bit of messing around with xml and then having to parse a number of files that are listed in the xml files to get your results. However the code is quite easy to modify so that you could do things such as list allocated vCPUs, or total allocated memory.
I’ve uploaded the code to github here.