Most administrators manage their VMware ESXi infrastructure using the vSphere Client. If you’re used to working...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
from the command line, however, the vSphere Command Line Interface offers a powerful alternative for ESXi management.
Downloading and installing vCLI
You can download the vSphere Command Line Interface (vCLI) from VMware’s website and install it on Windows and Linux workstations. You don’t need to purchase additional licensing to work with vCLI, but you do need to log in to your VMware account. After you log in and download vCLI, you can start the installation process.
When you install vCLI, it copies its available commands to your management workstation. You can find them in the C:\Program Files\VMware\VMware vSphere CLI\bin directory. It’s important to note that this directory is not included in the default Windows PATH variable, but you can change that variable to make it easier to run commands from the directory.
First, select Start > Control Panel > System and Security > System > Advanced. Then, select Environment variables. Locate the PATH variable and at the end of it, add :C:\Program Files\VMware\VMware vSphere CLI/bin. Now you can run vCLI commands directly from the command line, without first navigating to that directory. To activate your changes to the Windows path, log off and log on again.
Setting up the vCLI
Once you’ve installed the vSphere Command Line Interface, it’s time to test that everything works as expected. You can do this by using the basic command vmware-cmd --server yourserver -l. This command will prompt you for your login credentials, then list all the virtual machines (VMs) that are available on your ESXi host. Check that the command does its job and that the information is correct.
Using vCLI commands can be very convenient, but you probably don’t want to enter your user credentials every time you run a command. One way to avoid this is by using the --username and --password option in the command you want to run. For instance, enter that text at the end of the command: vmware-cmd --server yourserver -l --username root --password password .
The problem with this approach, however, is that the password is entered in plain text and therefore may compromise security. A more secure method is to work with a session file. This creates a file in which your credentials are cached for 30 minutes. Here’s how to create a session file:
- Activate the directory C:\Program Files\VMware\VMware vSphere CLI\Perl\apps\session.
- Run the command save_session.pl --savesessionfile \tmp\session --server yourserver --username root.
- Enter the password for the specified user.
To refer to the session file, include the --sessionfile parameter in every vCLI command you run:
vicfg-nics.pl --sessionfile \tpm\session -l
If this example works correctly, you'll now see a list of network interface cards that are installed on your ESXi host. Now you know how to simplify the process for running vCLI commands, and you can use these commands to manage your ESXi infrastructure much in the same way you'd use the vSphere Client.