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.

Deploying the vMA appliance, authentication and authorization and configuring fastpass

Firstly we will need to download the vMA appliance (https://my.vmware.com/web/vmware/details?downloadGroup=VMA55P01&productId=408) and import the OVF file, configure the deployment settings and power on.

Before we start using the vMA we will look at configuring authentication and authorization to simplify the use of the vMA appliance.

Configuring Authentication and Authorization for the vMA

To simplify executing commands agaisnt a remote host you can join the vMA to an Active Directory domain. In order to join the vMA to the domain invoke ‘domainjoin-cli‘ with elevated privelages as below. Once the vMA appliance has been succesfully configured to authenticate to the Active Directory domain you will be required perform a reboot.

domainjoin-cli join dean.local administrator
Joining to AD Domain: dean.local
With Computer DNS Name: localhost

administrator@DEAN.LOCAL's password:
Warning: System restart required
Your system has been configured to authenticate to Active Directory for the
first time. It is recommended that you restart your system to ensure that all
applications recognize the new settings.


Now we have enabled the vMA appliance for Active Directory authentication, we need to ensure that each ESXi hosts to be managed by the vMA appliance is also joined to the Active Directory domain, if this is not the case.

This can be achieved by selecting ‘Manage > Authentication Services > Join Domain’ for each managed host suing the Web Client.

Alternatively, I previously wrote an article on how to join multiple ESXi hosts to an Active Directory domain in the following post using PowerCLI – https://deangrant.wordpress.com/2014/07/29/powercli-joining-an-esxi-host-to-an-active-directory-domain/

Once the ESXi host has been joined to the domain you will need to configure permissions on each host for a domain user account or group. Now we will connect to the vMA and connect to one of hosts to retrieve the list of physical network adpaters as below.

esxcfg-nics -l --server deanesxi1.dean.local --username root
Enter password:
Name PCI Driver Link Speed Duplex MAC Address MTU Description
vmnic0 02:00.0 e1000 Up 1000Mbps Full 00:50:56:81:64:c3 1500 Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

However, as we have configured Active Directory for both the vMA and each ESXi hosts, we can use the fastpass functionality so there is no need to add user credentials to be passed to each command. The functionality of fastpass stores the user credentials for future use, by using the below command to add each ESXi host.

localhost:/home/vi-admin # vifp addserver deanesxi1.dean.local --authpolicy adauth
Enter username for deanesxi1.dean.local: dean\deangrant

You can confirm a list of servers to which fastpass has been configured for each target ESXi host.

localhost:/home/vi-admin # vifp listservers
deanesxi1.dean.local ESXi

Once fastpass is configured, you can connect to the the target host and invoke your command without the need to enter user credentials, as below to retrieve the list of physical network adapters.

vifptarget -s deanesxi1.dean.local
[deanesxi1.dean.local]# vicfg-nics -l

Name PCI Driver Link Speed Duplex MAC Address MTU Description
vmnic0 02:00.0 e1000 Up 1000Mbps Full 00:50:56:81:64:c3 1500 Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

Update a standalone ESXi server using vSphere CLI

I recently implemented a branch office in a box (BOB) scenario using the free edition of the ESXi hypervisor, one of the number of maintenance tasks that will need to be performed is to update the OS and therefore I decided that the method of deploying these updates will be to use the vSphere CLI to connect to a depot and install the update. This can be performed by using the following steps;

1) Run the VMware vSphere CLI and browse to the ‘C:\Program Files\VMware\VMware vSphere CLI\bin’ directory.

2) Enter host into maintenance mode by using the following command:

vicfg-hostps.pl –server <ESXi server> –operation enter

3) Copy the update file to the root of the datastore on the host.

4) Following the host being place in maintenance mode install the update, specifying the update file path in Step 3 as the depot.

esxcli.exe –server <ESXi server> software vib update –depot=/vmfs/volumes/<datastore>/<update>.zip

5) Once the update is completed successfully you may be prompted to restart the system for the changes to be effective.

6) Restart the host if prompted in Step 5 using the following command:

vicfg-hostps.pl –server <ESXi server> –operation reboot

7) Exit the host from maintenance mode using the following command:

vicfg-hostps.pl –server <ESXi server> –operation exit