I am just playing around in my lab and needed to do a couple of common ESXi commandline tasks which I figured I would document as they will come in handy at some point.
- List all VMs registered to this host (This reveals the Vmid needed for other commands)
vim-cmd /vmsvc/getallvms
- Unregister a VM
vim-cmd /vmsvc/unregister <Vmid>
- Register a VM
vim-cmd /solo/register /path/to/file.vmx
- Get power state of a VM
vim-cmd /vmsvc/power.getstate <Vimid>
- Power off a VM
vim-cmd /vmsvc/power.off <Vmid>
- Power on a VM
vim-cmd /vmsvc/power.on <Vmid>
tom miller says
Thanks. Nice to know the replacement comand for vmware-cmd. Have to figure out how to commit a snapshot from the command line. vCenter looses track of large snapshot commits
Thanks
Askar Kopbayev says
Interestingly, when you unregister a VM hosted on EXSi server which is registered with vCenter you will get orphaned VM in vCenter inventory.
Forbes Guthrie says
Thanks Duncan, very handy.
VMware’s ESXi 5.0 reference poster that they gave away at VMworld unfortunately lists all the vmware-cmd commands.
Although there is no esxcli replacement for these ones yet, I like the
esxcli vm process list
one. Its my “always run this as a quick check before I reboot the server” rule 🙂Forbes Guthrie says
BTW, according to this document (last page):
http://pubs.vmware.com/vsphere-50/topic/com.vmware.ICbase/PDF/vsphere-esxi-vcenter-server-50-command-line-management-for-service-console-users.pdf
The “vmware-cmd” command is still available in the vCLI (and presumably by extension in vMA 5.0 although I haven’t checked), just not on the ESXi shell. No doubt it will get removed soon and replaced with an esxcli command, but I thought I would point it out as its an inconsistency which is likely to cause confusion.
Incidentally the section above that in the PDF talks about an “esxcli filesystem vmfs” which I couldn’t see.
Jeremy Oakey says
I’ll add one experience I’ve had before when using these handy cli commands. I had put a host in Maintenance mode the night before but had forgotten and couldn’t get my vCenter VM to power on via the vmsvc/power.on method the next day. When your host is in Maintenance Mode, and you use the power.on command, you receive a very generic “Power On Failed” error message.
You can check the maintenance mode status of the host using
‘vim-cmd hostsvc/hostsummary | grep Maintenance’
and you’ll see a true or false line returned by the command – “inMaintenanceMode = true”
You can exit maintenance mode so that the power.on command will work using
‘vim-cmd hostsvc/maintenance_mode_exit’
(and ‘vim-cmd hostsvc/maintenance_mode_enter’ is the command to enter maintenance mode)
Darren says
Hello there Duncan,
I have been using vSphere for some years now and would like to get more in trenched in the command line admin for esxi.
Is there a more robust list of commands that I can access in the same style as you have doco’d here? or a good site that will help me learn the command line for esxi over the next 357 days?
trulyasian says
Thank you.Thank you.Thank you.Thank you.Thank you.Thank you.Thank you.Thank you.
you are a life saver.
I am trying to find a simple command to get all vms on a system, and web is full too much information about what you don’t need.