Occasionally I come across a VM that’s stuck.  Usually it’s resources on the VM that have been exhausted.  For whatever reason I cannot connect to a system on the network with the vSphere Client installed so I cannot connect to the host to shut down the VM.

Yes this happens.  Typically on networks where the VM in question is the DC and the only DNS source.  My agents drop offline because they cannot resolve anything and can no longer find my server.  If they can’t connect to me – I can’t connect to them.

Anyway, as a back door I usually do enable SSH to the ESXi host (I know it’s not recommended) and connect that way to get done what I need.

Once connected to the ESXi host via SSH:

esxcli vm process list

This command lists all of the VM’s running.  In particular I am interested in the World ID.

Once I have the World ID:

esxcli vm process kill -t [soft|hard|force] -w WorldID

Give it a few seconds then check the state of the VM by rerunning the process list command again. The VM should no longer be showing.

Now you may need to power up the VM.  You’ll need the vmid to power on the system.

vim-cmd vmsvc/getallvms

The VM’s will all be listed and have a number such as “1” or “2”:

Vmid               Name                                                    File                                             Guest OS         Version                                                                                                                                                                                                                                                                                                                                                                             Annotation
     SERVER1-DC                   [datastore2] SERVER1-DC/SERVER1-DC.vmx                                   windows8Server64Guest   vmx-08
2      SERVER2-SQL                  [datastore2] SERVER2-SQL/SERVER2-SQL.vmx                                 windows8Server64Guest   vmx-08

Now get the power state of the VM:

vim-cmd vmsvc/power.getstate <vmid>

You’ll see a response like this:

~ # vim-cmd vmsvc/power.getstate 1
Retrieved runtime info
Powered off

Power on the VM:

vim-cmd vmsvc/power.on <vmid>

Check the power state again.  It should show as “Powered on”.