Working with VMWare it’s a continues challenge, with new surprises every day, but fortunately, so far, only with happy endings. Let’s see today’s story.

I am working for a client that has a vCenter with 6 ESXi hosts. In order to access it, I have to start a VPN, then connect to a Windows terminal server via RDP and from this machine again via RDP to another Windows terminal server. So the second Windows machine is actually the management machine of the vCenter, from here I can access the vCenter’s web client to check and maintain the hosts and the virtual machines. The management Windows Server is running as a VM in this Cluster.

In the last few days I’ve upgraded the VMWare infrastructure to version 6.5 and now I noticed that the management machine needs to update the VMWare tools. I am aware that the machine will have to restart in order to complete the installation, and my connection will drop, but I am ok with that. I said to myself that it could not take more than 10 minutes, so I will reconnect again in a few minutes.

As expected, connection to the Windows management machine dropped. Now I am on the first Windows terminal server. 10 minutes later, RDP to the management machine is not responding. Hmm… I’ll wait 10 minutes more… Still not responding, ping is also not responding. Damn, it seems I cut the branch I was sitting on. I started slowly to get concerned but in the same time to think to another way to get back the control of vCenter.

The other VMs are running without any problems, I can access and check them from the first Windows terminal server. That is a relief. So the problem is only with the Windows management VM.

vCenter web client could not be accessed from the first Windows machine, I knew this, but I’ve wanted to check if at least I am having ssh connection. And yes, I am having, I managed to connect to vCenter. I do know I shouldn’t have SSH enabled, but luckily for me it is.

Now the question is – is that a way to restart a VM from SSH? I never did it so far. Quick searched Internet and found that is possible only from ESXi, not from vCenter. Didn’t have to much time to investigate, from ESXi should be also ok. Checked ssh connection on ESXi hosts and it’s also enabled. The chance is with me once more.

Now all I have to do is to find on which host is running my crazy Windows system. It’s good that there are only 6 hosts, not 20. I found it on 5th host. Fair enough!
After this very long introduction let’s see some commands.

Step one – list VMs running on ESXi hosts

In order to identify the right VM, you have to connect to the ESXi host via SSH and issue this command to list all VMs:

vim-cmd vmsvc/getallvms

Note: The screenshots have been taken in my Lab and not in the customer’s environment. I’m having two Windows systems here.

Step two – get VM state

To get the current state of the VM, issue the command:

vim-cmd vmsvc/power.getstate VMID

As you can see, one VM is Powered on, and the other one is Powered off.

Step three – power shutdown VM

You can run an incomplete command and see all the commands available:

vim-cmd vmsvc/power.

Shutdown the VM using this command:

vim-cmd vmsvc/power.shutdown VMID

If the VM fails to shutdown, you can run:

vim-cmd vmsvc/ VMID

vim-cmd vmsvc/power.on VMID 

In my case, I couldn’t shutdown the VM, I had to power off first and then power on. After that, Windows started and I could connect to it.

More information about these procedures here.

Lesson learned, mission accomplished!


1 Comment

  1. Thanks for this page. It’s basically my first introduction to command line vmware. In my case, the guest has been “shutting down” for 1/2 an hour. So I look for a way to force the task. No luck. When I run the commands, I get told that a task is already in progress. But still, the information is most helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *