Powering off a virtual machine using ESXCLI

In a number of instances you may not be able to gracefully power off a virtual machine using the Web Client or the vSphere Client when directly connected to the ESXi Host.

In this instance you will be required to use the command line interface and this example the esxcli command to power off the virtual machine.

You will be required to connect to the console session to be able to invoke the esxcli, whether this being the ESXi shell, vMA or using the vCLI.

In order to power off the virtual machine you will be require the World ID number, this can be retrieving by invoking:

esxcli vm process list

This will retrieve all the virtual machines that are running on the ESXi host, search for the virtual machine you require to power off and make a note of the World ID. In the example below I am required to power off ‘vm123’ with the World ID of ‘25104756’.

 World ID: 25104756
 Process ID: 0
 VMX Cartel ID: 25104753
 UUID: 42 0c 78 4a aa ac ad 88-d9 41 5d fd c2 28 3c d5
 Display Name: vm123
 Config File: /vmfs/volumes/5461cf1a-73d683d3-fa4e-00221988e761/vm123/vm123.vmx

In order to power off the virtual machine we will again invoke the esxcli command with the kill option, where the type is ‘soft’.

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

As per knowledge base article (http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1014165) there are three power off methods available:

Soft is the most graceful, hard performs an immediate shutdown, and force should be used as a last resort.

To validate the virtual machine has been powered off, list the virtual machines using ‘esxcli vm process list’ to confirm this is no longer running.

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