Killing a stuck VM (guest) by 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…
Comments
Post a Comment