Tip

VMware vSphere Command Line Interface: Using vCLI for ESXi management

Most administrators manage their VMware ESXi infrastructure using the vSphere Client. If you’re used to working from the command line, however, the vSphere Command Line Interface offers a powerful alternative for ESXi management.

    Requires Free Membership to View

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.


Figure 1
You'll need to enter your user credentials for every vCLI command you run. (Click image for an enlarged view.)

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:

  1. Activate the directory C:\Program Files\VMware\VMware vSphere CLI\Perl\apps\session.
  2. Run the command save_session.pl --savesessionfile \tmp\session --server yourserver --username root.
  3. 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.

This was first published in December 2011

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.