ESXi Command to Shut Down Virtual Machines | How to Shut Down a VM via ESXi Commands

ESXi命令关闭虚拟机 | ESXi怎么用命令对VM关机

For VMware administrators, there are times when a virtual machine becomes unresponsive—perhaps due to issues like snapshot operations or disk contention that cause it to hang. In these cases, the VM may appear frozen, the console becomes inaccessible, and attempts to power it off via vCenter or directly on ESXi either fail, have no effect, or even display a message such as “another task is in progress.” In short, the VM cannot be shut down using conventional methods.

This article explains how to use the ESXi command line—specifically the esxcli command—to forcefully shut down such problematic virtual machines and help restore normal operations.

We have two sets of ESXi commands that can be used to shut down a VM via the command line. The recommended method is the esxcli vm process kill command because it is quicker and does not require VMware Tools to be installed on the VM.

Let’s assume that our first virtual machine, named New Virtual Machine, cannot be shut down via vCenter’s power-off option. In this case, we need to use the command line to power it off.

First, SSH into the ESXi host or use the server’s remote management console (such as iDRAC or iLO) to access the ESXi orange-black DCUI console.

Method 1: Using the esxcli vm process kill Command

You can combine the following two commands:

esxcli vm process list
esxcli vm process kill --type=[soft,hard,force] --world-id=WorldNumber

List Running VMs:
The first command, esxcli vm process list, displays all running virtual machines. Locate the VM that needs to be shut down and note its World ID.
For example, you might see that the VM’s World ID is 2103991.

Shut Down the VM:
Next, use the esxcli vm process kill command to shut down the VM:

esxcli vm process kill --type=soft --world-id=2103991 

If the command returns no error or output, it indicates that the VM has been successfully shut down. Running the esxcli vm process list command again should confirm that the VM is no longer listed, and a check in vCenter will verify that the VM has powered off.

Shutdown Types:
The --type option supports three shutdown methods:

  • soft
  • hard
  • force
Their differences are as follows:

soft:
Always try a soft shutdown first. This method gives the VMX process a chance to close gracefully (similar to using kill or kill -SIGTERM).

hard:
If a soft shutdown does not work, try a hard shutdown, which immediately terminates the process (similar to using kill -9 or kill -SIGKILL).

force:
The force option should be used only as a last resort to shut down the VM. If none of these methods succeed, a reboot of the host may be required.

Method 2: Using the vim-cmd vmsvc Commands

Alternatively, you can use the following sequence of commands:

vim-cmd vmsvc/getallvms
vim-cmd vmsvc/power.getstate VMID
vim-cmd vmsvc/power.shutdown VMID
  1. Get All VMs:
    The command vim-cmd vmsvc/getallvms lists all VMs registered on the ESXi host (including those that are powered off). Identify and record the VMID of the virtual machine you want to shut down.
  2. Check VM Power State:
    Next, use vim-cmd vmsvc/power.getstate VMID to check the power state of the VM.
    For example, you might observe that the VM with VMID 1 is in the “Powered On” state while another VM is off.
  3. Shut Down the VM:
    Finally, execute: arduinoCopyEditvim-cmd vmsvc/power.shutdown 1 Running this command for VMID 1 (representing the New Virtual Machine) should power it off. The absence of any output indicates that the shutdown was successful.

Note: The vim-cmd method requires that VMware Tools is installed on the VM. If VMware Tools is not running, you may encounter an error similar to:

(vim.fault.ToolsUnavailable) {
faultCause = (vmodl.MethodFault) null,
faultMessage = msg = "Received SOAP response fault from []: shutdownGuest
Cannot complete operation because VMware Tools is not running in this virtual machine."
}

This concludes the translation of the technical article on using ESXi commands to shut down virtual machines.

图书推介 - 京东自营

24小时热门

还有更多VMware问题?

免费试下我们的VMware技术助理(已接Deepseek)!即时解答VM难题 → 🤖VM技术助理


########

扫码加入VM资源共享交流微信群(请备注加群

需要协助?或者只是想技术交流一下,直接联系我们!

推荐更多

vCenter虚拟机硬盘显示0GB | VMware虚拟机硬盘显示0GB
how-to

vCenter Virtual Machine Disk Shows 0GB

Encountering a situation where all virtual machine disks in vCenter show 0GB and options are greyed out? This issue often stems from an SSL certificate mismatch. In this guide, we walk you through diagnosing the problem and fixing it using VMware’s lsdocter script.

ESXi 9.0只支持UEFI启动,不再支持传统BIOS?
what-is

ESXi 9.0 Only Supports UEFI Boot – Is Legacy BIOS on Its Way Out?

VMware is moving towards a UEFI-only boot model, and ESXi 9.0 may completely drop legacy BIOS support. A recent blog by VMware architect William Lam and official VMware KB articles reinforce this shift. Administrators should assess their ESXi hosts and plan for a transition to UEFI to ensure future compatibility and security.