If you're a VMware admin, you know the vSphere client well. But you may only use the relatively new esxcli command series when forced for troubleshooting or other obscure purposes.
When vSphere 4 was released, VMware introduced the esxcli command series, but it was primarily used for storage. Since then, VMware has enhanced the esxcli command set to do just about anything from the command line, making older command-line tools, such as the esxcfg and vicfg series, obsolete.
Esxcli breaks down into the following administration topics, each with its own extensive list of subcommands:
- esxcli command
- esxcli fcoe
- esxcli hardware
- esxcli iscsi
- esxcli license
- esxcli network
- esxcli software
- esxcli storage
- esxcli system
- esxcli vm
With so many uses for esxcli, start with these 10 ways to use esxcli commands if you want to get started on testing and learning.
1. Manage hosts.
You can manage hosts using esxcli system and options such as shutdownpoweroff or shutdown reboot. To execute the shutdown, you must specify the reason with the -reason option. You can enable or disable maintenance mode on ESXi hosts with system maintenancemode set -enable true or false.
VMware expert Chris Colotti shares how to use esxcli software vib install to patch your ESXi hosts from the command line without using vSphere Update Manager.
Besides host maintenance and updating, you can use esxcli system to manage VMkernel modules.
2. Manage storage paths.
Esxcli started by offering storage functionality, and it's still the best tool to troubleshoot and manage storage. To list path information about Fibre Channel (FC) or iSCSI logical unit numbers (LUNs), you can use esxcli storage core path list. You can also list adapters with storage core adapter list and re-scan adapters with storage core adapter rescan.
When you want to make changes, you can set the state of a path with storage core path set -- state off or active.
3. Connect to NAS.
Want to connect to network file system (NFS) network-attached storage (NAS) from the command line? You can use esxcli storage nfs add to connect an ESXi host to an NFS NAS. You can list all current NFS connections using esxcli storage nfs list.
4. Check Fibre Channel events.
If you're having trouble with FC connections, you can use esxcli storage san fc events get to list any events related to FC and Fibre Channel over Ethernet devices. To clear the log, use events clear and specify the adapter whose lot you want to clear.
5. Re-scan storage adapters.
Periodically, you will need to re-scan your storage adapters to recognize added or removed storage devices. The easiest way to do it from the CLI is to use esxcli storage core adaptor rescan.Optionally, you can add to scan all adapters, scan a specific adapter, skip specific devices, skip the file system scan or only scan for certain types of changes.
6. Retrieve SMART Information.
If you have Self-Monitoring, Analysis and Reporting Technology (SMART) disks, your disks know when they are having trouble. With SMART, the drives can warn you before they fail so you can use vMotion to move running virtual machines to another LUN or array before disaster strikes. To see SMART disk information from the CLI on an ESXi host, use esxcli storage core device smart get -d device.
7. Control virtual machines.
While the vmware-cmd tool is still useful, you can control virtual machines with esxcli. For example, if you wanted to list all the IDs of the virtual machines running on your ESXi server and then stop a particular VM, you would execute the following:
esxcli <conn_options> vm process list
esxcli <conn_options> vm process kill --type <kill_type> --world-id <ID>
8. Manage the virtual network.
Did you know that esxcli can also manage the virtual network? To list all interfaces, and then information on a particular interface, use the following:
esxcli <conn_options> network ip interface list
esxcli <conn_options> network ip interface ipv4 get -n vmk<X>
9. Take control of esxcli vSAN management.
New with vSphere 5.5 is the option to manage VMware Virtual SAN (vSAN) from the command line using esxcli. All commands start with esxcli vsan, and options after include cluster, datastore, network, policy, storage and trace. For example, to list the vSAN storage configuration you would run the following:
esxcli vsan storage list
10. Control output.
Just about any esxcli output can be formatted and sent to a CSV file using the formatter option, like this:
esxcli --formatter=keyvalue storage filesystem list > myfilesystemlist.txt
For reference on more esxcli options, visit the vSphere 5 Command-Line Documentation.