Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Cool vSphere Command-Line Interface (ESXCLI) Commands that Helped Me a Lot

  • April 22, 2019
  • 11 min read
Cloud and Virtualization Architect. Kevin focuses on VMware technologies and has vast expertise in cloud solutions, virtualization, storage, networking, and IT infrastructure administration.
Cloud and Virtualization Architect. Kevin focuses on VMware technologies and has vast expertise in cloud solutions, virtualization, storage, networking, and IT infrastructure administration.

Today, I’d like to share some of cool ESXCLI commands for performing a good part of IT related routines. Sure, vSphere Client has a wonderful GUI allowing for carrying out most of daily tasks… but CLI is much more powerful tool once you master it! So, that’s actually why I share my “Swiss Army knife” commands here.

Cool ESXCLI commands

Why one still needs CLI in vSphere?

Don’t overlook the command line… It can be a useful tool for performing a wide range of tasks that just cannot be done via vSphere Client. CLI also provides a room for automatizing routine tasks. And, last but not least, CLI is a powerful tool for troubleshooting. You can learn more about vSphere CLI commands here: https://pubs.vmware.com/vsphere-6-5/index.jsp?topic=%2Fcom.vmware.vcli.ref.doc%2Fvcli-right.html.

The nice thing about ESXi is that it was built on the Linux kernel. So, everybody who has ever had hands-on experience with Linux already has some commands in their “arsenals” (that’s why I start with Linux commands today).

Some standard Linux commands that are good to know

1. help – as its name implies, this command provides a comprehensive summary of any other command. I believe it to be one of the most important commands ever.

This command provides a comprehensive summary of any other command

2. less is a useful command for working with long outputs. With less, you can display them in a page-by-page fashion that is just far more convenient way to work with them.

less is a useful command for working with long outputs

3. grep allows applying some filters to outputs to find specific lines easier.

grep allows applying some filters to outputs to find specific lines easier

4. more – display outputs screen-by-screen.

more – display outputs screen-by-screen

5. esxcli esxcli command list | more lists all ESXCLI commands and their descriptions.

More lists all ESXCLI commands and their descriptions

6. dcui starts an SSH session to work with the server console.

dcui starts an SSH session to work with the server console

7. cd enables to change the current directory.

8. mkdir allows for creating directories.

mkdir allows for creating directories

9. ls returns directory contents (i.e., listing all the files and sub-directories).

ls returns directory contents

10. mv – moving or re-naming a specific file or directory.

mv – moving or re-naming a specific file or directory

11. ps displays info on all active processes.

ps displays info on all active processes

ps displays info on all active processes

12. cp – copying directories or files. With this command, you can copy individual files or multiple files in one go. By the way, you can rename files while copying them (which is sometimes really handy).

cp – copying directories or files

13. find – template-driven search for files.

 find – template-driven search for files.

14. cat – reading from files and outputting them at the screen.

 cat – reading from files and outputting them at the screen.

Doing routines with CLI

Now, I’m going to share with you some ESXCLI commands for performing routine tasks. Sure, you may already know some of them, but admins who are just getting used to ESXi may find them interesting.

1. reboot – as the name implies, this command enables to reboot the host.

2. poweroff – power-off the host from the command line.

3. esxcli system version get – get some info on the installed VMware ESXi version

Doing routines with CLI

4. esxcli hardware – find out more about the host hardware.

esxcli hardware – find out more about the host hardware

5. esxcli hardware pci list – get the comprehensive information on all available PCI devices.

esxcli hardware pci list – get the comprehensive information on all available PCI devices

6. esxcli hardware clock (get/set) – getting or setting up ESXi system time.

esxcli hardware clock (get/set) – getting or setting up ESXi system time

7. lspci – brief info on available PCI devices.

lspci – brief info on available PCI devices

lspci – brief info on available PCI devices

8. esxtop – monitoring host resource utilization. Here are the hotkeys for switching between views: C (CPU), I (interrupt), M (memory), N (network), D (disk adapter), U (disk device), V (virtual disk), P (power mgmt).

esxtop – monitoring host resource utilization

esxtop – monitoring host resource utilization

9. vmkerrcode -l – provides more details on error codes. Just type this command next time when something goes wrong with a VM.

vmkerrcode -l – provides more details on error codes

10. esxcfg-nics – returns details on NICs.

esxcfg-nics – returns details on NICs

11. esxcfg-vswitch – provides additional info on the virtual switch.

esxcfg-vswitch [options] [vswitch[:ports]]

12. chkconfig -l shows the status of all services in all runlevels.

chkconfig -l shows the status of all services in all runlevels

13. esxcli software – Software namespace that includes commands for managing and installing profiles and VIBs.

14. esxcli software vib list lists all installed VIBs.

esxcli software vib list lists all installed VIBs

15. esxcli network – network namespace for managing virtual networking (i.e., vNICs and switches).

16. esxcli network ip connection list lists all the active connections.

esxcli network ip connection list lists all the active connections

17. esxcli storage – a bunch of core storage commands and other commands for managing storage.

18. esxcli storage vmfs extent list lists extents for VMFS volumes.

esxcli storage vmfs extent list lists

19. esxcli system – storage monitoring and management command.

20. esxcli system version get returns ESXi version and build number.

esxcli system version get returns ESXi version and build number

21. uname  provides comprehensive info on VMware ESXi version.

uname  provides comprehensive info on VMware ESXi version

Commands for managing VMs

1. vim-cmd vmsvc/getallvms provides information about VMs running on a specific host (i.e., Vmid, Name, File, Guest OS, Version, Annotation).

vim-cmd vmsvc/getallvms

2. vim-cmd vmsvc/power.getstate # – use this command to see whether the VM is running or not. Just enter its Vmid instead of #.

vim-cmd vmsvc/power.getstate #

3. vim-cmd vmsvc/power.on/off # – power on and off the specific VM. Replace # with Vmid.

4. vim-cmd vmsvc/power.reset # – resetting the VM. Enter Vmid

5. vim-cmd vmsvc/power.shutdown # – shutting down gracefully the specific VM.

6. vim-cmd vmsvc/power.reboot # – rebooting the VM.

7. vim-cmd vmsvc/get.summary # provides comprehensive information about the VM.

8. esxcli vm process list returns the list of running VMs and their World IDs.

esxcli vm process list

9. esxcli vm process kill -type=[soft,hard,force] -world-id=WorldID gives you a bunch of options for stopping a VM with specific World ID.

  • soft – VMX is stopped gracefully.
  • hard – VMX is stopped immediately.
  • force – well, call it the last resort… Use force-stop only like restarting the host.

10. vim-cmd solo/registervm /vmfs/vol/datastore/dir/vm.vmx registers VM in the hypervisor inventory and assigns a Vmid to it.

vim-cmd solo/registervm /vmfs/vol/datastore/dir/vm.vmx

11. vim-cmd vmsvc/unregistervm vmid # – deleting the VM with specific Vmid from the inventory.

Conclusion

Sure, I did not list here all the ESXCLI commands that may come in handy. Nevertheless, I believe the ones mentioned in this article to be a “bare minimum” that helps beginners a lot. With these commands, you can perform some of IT related routines like managing VMs and ESXi host. I hope, today’s article helps you!

Hey! Found Kevin’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!