Home > PowerCLI, PowerShell, vSphere > How to Hard Kill a stuck VM with PowerCLI

How to Hard Kill a stuck VM with PowerCLI

Sometimes a VM is stuck and can’t be killed with vSphere Client (or from within the VM).

On ESX, you could login and perform the famous kill –9 <PID> to kill the VM.  Most people don’t realize that this functionality has been added to PowerCLI in version 4.1 Update 1.

First, connect directly to the ESX(i) host.

Connect-VIServer -Server <Hostname> -Credential $(Get-Credential -Credential root)

It will ask you for the root password.


Next, fetch a ESXCLI object with the Get-ESXCLI cmdlet.

$esxcli = Get-EsxCli -Server <Hostname>

Run the following method of $esxcli to list all the running VMs and their World ID.

$esxcli.vms.vm.list() | Format-Table -Property DisplayName, WorldID



Look up the WorldID of the VM you want to kill.

Run the following method of $esxcli to kill the VM.

$esxcli.vms.vm.kill("soft", <WorldID>)



If it reports back with true it means the VM was killed successfully.  If you get false, try replacing soft by hard and finally by force.  Use force only as a last resort.

The possible killtypes are:

KillType Description
soft Try to perform a proper VM World shutdown (the old ‘kill <PID>’)
hard Hard kill of the VM World (the old ‘kill –9 <PID>’)
force Use all dirty tricks available to kill the damn bastard.  Use only as a last resort!


If these won’t allow you to kill the VM, you can only reboot the host and hope no data has been lost…

Categories: PowerCLI, PowerShell, vSphere
  1. Suresh
    October 4, 2011 at 10:35

    It’s awesome!!! Keep it coming….

  1. September 8, 2011 at 14:56

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: