
This assumes you have enabled SSH connections to your ESX hypervisor. The vim-cmd vmsvc/getallvms command can be used to list each registered virtual machine.
vim-cmd vmsvc/getallvms
Something like this should be returned.
Vmid Name File Guest OS Version Annotation
33 vm1.example.com [datastore_VMs] vm1.example.com/vm1.example.com.vmx centos64Guest vmx-11
37 vm2.example.com [datastore_VMs] vm2.example.com/vm2.example.com.vmx centos64Guest vmx-11
54 vm3.example.com [datastore_VMs] vm3.example.com/vm3.example.com.vmx fedora64Guest vmx-13
The vim-cmd vmsvc/power.getstate <id> command can be used to determine if a virtual machine is currently powered on or off.
vim-cmd vmsvc/power.getstate 33
In this example, the vm1.example.com virtual machine is currently powered off.
Retrieved runtime info
Powered off
The vim-cmd vmsvc/power.on <id> command can be used to power on a virtual machine.
vim-cmd vmsvc/power.on 33
Something like this should be returned.
Powering on VM:
To power off a virtual machine, whenever possible, the virtual machine should be powered off via the guest virtual machine. For example, if the virtual machine is a Linux system, the shutdown command should be used to power off the virtual machine. However, if for whatever reason it is not possible to shutdown the virtual machine via the guest, you would first use esxcli vm process list command to get the world ID of the virtual machine. Let's say the esxcli vm process list command returns the following. In this example, the world ID of vm1.example.com is 75260.
vm1.example.com
World ID: 75260
Process ID: 0
VMX Cartel ID: 75259
UUID: 56 4d c9 05 de c1 72 0f-6a c7 e8 23 5f d6 cd be
Display Name: vm1.example.com
Config File: /vmfs/volumes/57657886-7b8f67a9-b213-10bf4879952f/vm1.example.com/vm1.example.com.vmx
The esxcli vm process kill <world id> command would then be used to kill the virtual machine process.
esxcli vm process kill 75260
Then you would use the vim-cmd vmsvc/getallvms command to get the ID of the virtual machine. In this example, the ID of vm1.example.com is 33.
Vmid Name File Guest OS Version Annotation
33 vm1.example.com [datastore_VMs] vm1.example.com/vm1.example.com.vmx centos64Guest vmx-11
You would then use the vim-cmd vmsvc/power.off <id> command to power off the virtual machine.
vim-cmd vmsvc/power.off 33
Something like this should be returned.
Powering off VM:
Did you find this article helpful?
If so, consider buying me a coffee over at