VMware vSphere Command Line Interface: Using vCLI for ESXi management

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

    When you register, my team of editors will also send you alerts covering all areas of VMware, such as implementing VMware-related virtualization technologies for server consolidation, disaster recovery and backup strategies, management and performance, VM migration and more.

    Margie Semilof, Editorial Director

    By submitting your registration information to SearchVMware.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchVMware.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    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.