Guide

ESXi command line: a cheat sheet of esxcli and vim-cmd commands

ESXi's command line has two tools that do nearly everything: esxcli for the host (storage, network, software, maintenance mode) and vim-cmd for virtual machines (list, power, snapshots). Turn on SSH in the Host Client, sign in as root, and they're there.

Below is a cheat sheet of the commands worth knowing on ESXi 7 and 8, grouped by job. For setting up and running an ESXi host day to day, see how to manage a VMware ESXi host remotely.

  • Turn on SSH first
  • esxcli for the host
  • vim-cmd for VMs

Updated · VMware ESXi 7 and 8

Turn on SSH and the ESXi Shell

  1. Step 1: From the Host Client

    Sign in to the Host Client, the host's own web page, and click Host in the navigator. Then choose Actions > Services > Enable Secure Shell (SSH). Enable console shell turns on the shell on the server's own screen as well.

  2. Step 2: Or at the server's console

    On the yellow and grey console screen, press F2, sign in, open Troubleshooting Options and choose Enable SSH. With the console shell on, Alt+F1 opens it on that screen.

  3. Step 3: Sign in

    From PowerShell, a Mac or Linux terminal: ssh root@esxi-01. If SSH is already on and you just need to start it again later, vim-cmd hostsvc/enable_ssh and vim-cmd hostsvc/start_ssh do it from the shell.

Turn it off when you're done

The Host Client shows a warning while SSH is on, and that's fair: switch it off again when you don't need it, and keep the host's management network off the internet.

Virtual machines (vim-cmd)

Most VM commands take the VM's Vmid, the number getallvms shows in its first column (2 in these examples).

vim-cmd vmsvc/getallvms                  # every registered VM with its Vmid
vim-cmd vmsvc/power.getstate 2           # Powered on / Powered off
vim-cmd vmsvc/power.on 2
vim-cmd vmsvc/power.shutdown 2           # clean shutdown from the guest (needs VMware Tools)
vim-cmd vmsvc/power.reboot 2             # clean restart from the guest (needs VMware Tools)
vim-cmd vmsvc/power.off 2                # pull the plug
vim-cmd vmsvc/get.guest 2                # guest details, including its IP address

esxcli vm process list                   # running VMs with their World ID
esxcli vm process kill --type=soft --world-id=1234567   # a stuck VM; then hard, then force

Snapshots, registering and copying disks

vim-cmd vmsvc/snapshot.get 2
vim-cmd vmsvc/snapshot.create 2 "before-update" "patch night" 0 0
vim-cmd vmsvc/snapshot.removeall 2       # delete (consolidate) all of its snapshots

vim-cmd solo/registervm /vmfs/volumes/datastore1/dns-02/dns-02.vmx
vim-cmd vmsvc/unregister 2               # removes it from the list, keeps its files

vmkfstools -i /vmfs/volumes/datastore1/dns-01/dns-01.vmdk /vmfs/volumes/datastore1/dns-02/dns-02.vmdk -d thin

In snapshot.create, the two zeros mean "don't include the memory" and "don't quiesce". The vmkfstools -i line copies a virtual disk as thin-provisioned, the usual first step of cloning a VM by hand on a host without vCenter.

The host: version, hardware and maintenance mode

esxcli system version get
esxcli system hostname get
esxcli hardware platform get
esxcli hardware memory get
esxcli software vib list                 # installed packages and drivers

esxcli system maintenanceMode set --enable true
esxcli system maintenanceMode get
esxcli system shutdown reboot -r "BIOS update"     # needs maintenance mode
esxcli system maintenanceMode set --enable false

A host only enters maintenance mode once its VMs are off (or moved, with vCenter), so shut them down first.

Storage

esxcli storage filesystem list           # datastores, size and free space
df -h
ls /vmfs/volumes/datastore1/
esxcli storage core device list          # disks the host can see
esxcli storage core adapter rescan --all

Network

esxcli network nic list                  # physical NICs, link and speed
esxcli network ip interface ipv4 get     # the host's own addresses
esxcli network vswitch standard list
esxcli network ip dns server list
vmkping -I vmk0 nas-01                   # ping from the host's management interface

Services and logs

/etc/init.d/hostd restart                # the host's management agent, if the Host Client stops answering
/etc/init.d/vpxa restart                 # the vCenter agent, on hosts managed by vCenter
tail -f /var/log/hostd.log
tail -f /var/log/vmkernel.log

Restarting hostd doesn't touch running VMs, but the Host Client and any vCenter connection drop for a minute.

Run these from RemoteAccessApp

Save the host in the RemoteAccessApp SSH client as an SSH host with a key or password, and the shell opens in a tab. Put the checks you run often in the terminal's Scripts & History panel, and run one on all your ESXi hosts at once with Run on hosts…, which shows each host's output and result. Stick to commands ESXi's shell has: it's a small shell, and many Linux tools aren't there.

Hosts on your home or office network can be reached through one of your own PCs there, so neither SSH nor the Host Client has to face the internet. Free on Windows and Linux for up to 5 saved hosts: download RemoteAccessApp. New to running a lab? Start with how to set up a homelab, and see the SSH client checklist for what to look for in an SSH app.

Questions, answered

More homelab and virtualization guides