Manage Learn to apply best practices and optimize your operations.

Use esxcli commands for vSphere management, troubleshooting

The esxcli command set provides administrators with an easy to use set of commands to configure, manage and troubleshoot a vSphere-based infrastructure.

The esxcli command set for VMware ESXi Shell exposes various hypervisor reporting and configuration tools within...

one application executable and is often used for troubleshooting.

Esxcli commands provide some useful functionality, especially for those who don't have vCenter to manage their VMware hosts. These commands also enable the vSphere administrator to reproduce identical output across several hosts because it's easy to copy and paste commands.

Esxcli requires Secure Shell (SSH) access to operate. SSH is disabled by default, so you need to enable SSH on stand-alone hosts to use esxcli commands. To access esxcli, use SSH to log in to a host as root. Once you're logged in, type esxcli to start experimenting with esxcli; keep in mind that everything is case-sensitive.

Building blocks of an esxcli command

The top-level namespaces, as seen in Figure A, show the major item groups available. Each namespace has multiple -- sometimes up to hundreds, or even thousands -- of lower-level options from which to choose.

Major esxcli components
Figure A. Each esxcli namespace has multiple lower-level options from which to choose.

To view namespace options, simply type in the name of the namespace and press Enter; the system will display all the available commands for that namespace and repeat this behavior all the way down the menu.

Certain commands only require the namespace to function, while others require the administrator to read out additional information or configure a system.

Certain commands only require the namespace to function, while others require the administrator to read out additional information or configure a system. Esxcli commands use verbs such as get and set to indicate what action you want the command to perform. The get verb recalls information, while the set verb sets information parameters.

For example, to use esxcli to recall the system hostname, enter the following command:

esxcli system hostname get

This esxcli command uses the system namespace, the hostname sub-option and the get verb to retrieve the information.

You can use an esxcli command to recall the system hostname.
Figure B. Use the get verb in an esxcli command to retrieve information.

To test out the set command, try setting the hostname to testhost with the following command:

esxcli system hostname set --host testhost

As you can see, most of the command is pretty straightforward, with the exception being that it uses an additional set command option. These options, such as --host for the physical host, --domain for the domain name and --fqdn for the fully-qualified domain name, act as system selectors and are often followed by a specific value -- in this example, testhost.

The common format for set commands is as follows:

esxcli namespace [sub-option] set [selector] [value]

You can use other esxcli namespaces to get information about the physical host, the iSCSI subsystem and the Network File System, or any other low-level information.

It's a good idea to experiment with different esxcli commands to get a better understanding of just how many commands there are and what information they can yield.

Esxcli enables greater functionality

Esxcli commands enable functionality that isn't available by other means. The common use for esxcli commands is to upgrade hosts. If you don't have vCenter to manage host upgrades, you can use esxcli instead. To do so, download the latest vSphere installation bundle (VIB) and enter the following command:

esxcli software install vib update --d /path/to/file

This esxcli command offers a convenient way to upgrade a remote host when there is no boot from CD media capability locally. Esxcli also offers a number of other commands that can install VIBs to install drivers and other required packages on the server.

Esxcli commands can also perform rudimentary VM management, which is very useful in emergency situations, such as when the management UI isn't working. To shut down a host as gracefully as possible, enter the following command:

esxcli vm process list

This command shows the running processes associated with the VM, as illustrated in Figure C.

The esxcli vm process list command in action
Figure C. Use the esxcli vm process list command to see all the VMs running on the host.

To kill nonresponding VMs, enter esxcli vm process kill into the command line. Although these commands are useful, you should be mindful and use them only when absolutely necessary.

This was last published in February 2018

Dig Deeper on Scripting administrative tasks

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

Which commands do you most commonly use in your infrastructure?