Assuming ssh access is enabled you can ssh into your esx server from a bash terminal i.e...
ssh {ESX IP Address}
Once logged you can run the following command...
vim-cmd vmsvc/getallvms
Which will produce a list of virtual machines on the server. The moid is in the first column.