

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.

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.

[some command] --help 1 [ some command ] -- help

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.

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

grep [-HhnlLoqvsriwFEz] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]... 1 grep [ - HhnlLoqvsriwFEz ] [ - m N ] [ - A / B / C N ] PATTERN / - e PATTERN . . . / - f FILE [ FILE ] . . .

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

[some command] | more more < [path] [file_name] 1 2 3 [ some command ] | more more < [ path ] [ file_name ]

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

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

7. cd enables to change the current directory.

сd [\] [path] [~/] [-]; 1 с d [ \ ] [ path ] [ ~ / ] [ - ] ;

8. mkdir allows for creating directories.

mkdir [some directory name] [-m] [-p] 1 mkdir [ some directory name ] [ - m ] [ - p ]

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

ls [-1AaCxdLHRFplinsehrSXvctu] [-w WIDTH] [FILE]... 1 ls [ - 1AaCxdLHRFplinsehrSXvctu ] [ - w WIDTH ] [ FILE ] . . .

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

mv [path and file name] [new path] [-f] [-i] [-n] 1 mv [ path and file name ] [ new path ] [ - f ] [ - i ] [ - n ]

11. 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 [some file 1] [some file 2] cp [some file 1] ... [some directory] cp -r [some directory] ... [some directory] 1 2 3 4 5 cp [ some file 1 ] [ some file 2 ] cp [ some file 1 ] . . . [ some directory ] cp - r [ some directory ] . . . [ some directory ]

13. find – template-driven search for files.

find [-HL] [PATH]... [OPTIONS] [ACTIONS] 1 find [ - HL ] [ PATH ] . . . [ OPTIONS ] [ ACTIONS ]

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

cat [FILE]... 1 cat [ FILE ] . . .

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

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

5. 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.

7. lspci – brief info on available PCI devices.

lspci [-p] [-n] [-d] [-e] [-v] [-h] 1 lspci [ - p ] [ - n ] [ - d ] [ - e ] [ - v ] [ - h ]

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).

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

10. esxcfg-nics – returns details on NICs.

esxcfg-nics [-s] [-d] [-a] [-l] [-e] [-r] [-h] 1 esxcfg - nics [ - s ] [ - d ] [ - a ] [ - l ] [ - e ] [ - r ] [ - h ]

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

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

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

chkconfig [options] 1 chkconfig [ options ]

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

esxcli software {cmd} [cmd options] 1 esxcli software { cmd } [ cmd options ]

14. esxcli software vib list lists all installed VIBs.

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

esxcli network {cmd} [cmd options] 1 esxcli network { cmd } [ cmd options ]

16. 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.

esxcli storage {cmd} [cmd options] 1 esxcli storage { cmd } [ cmd options ]

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

19. esxcli system – storage monitoring and management command.

system {cmd} [cmd options] 1 system { cmd } [ cmd options ]

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

21. uname provides comprehensive info on VMware ESXi version.

uname [-amnrspvio] 1 uname [ - amnrspvio ]

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).

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

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.

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.

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!