How to kill a hung VM (or task) in ESX or ESXi
Yesterday I received a call asking for assistance on a VM that was in an inoperative state in a ESX 3.5 environment. There was an active task to create a snapshot which was almost a day old and could not be cancelled. Any attempt to invoke a new task or change the power state resulted in “another task is already in progress”.
The good news here is that VMware has some very good KB articles that do a great job of detailing some of the options here. They have a KB article for ESX with the Service Console and another KB article for ESXi environments.
If you are in an ESX (Service Console) environment you also need to know how to use SSH (you can also use the physical server console or DRAC/ILO/KVM, but I prefer SSH). I use PuTTY which is available here. In an ESXi environment you can use the Remote CLI (which you will want to install on your workstation) to issue the commands as detailed in the ESXi KB article.
Now there may also be times where it is necessary to kill the task (i.e. creating or closing a snapshot) without affecting the VM state. You can follow the procedures in this KB article to restart the management agents on the ESX host or you can play the video below. Just keep in mind that this resets the connection between the host and vCenter and that some tasks (such as closing snaps) can take a long time and in some cases even exceed the timeout in vCenter even though the ESX host is still performing the task. Restarting the agents does not impact what the ESX host is doing (including hosting VMs) beyond resetting the connection with vCenter.