Getting Started with vSphere Command-Line Interfaces ESXi 6.5 vCenter Server 6.5 This document supports the version of each product listed and supports all subsequent versions until the document is replaced by a new edition. To check for more recent editions of this document, see http://www.vmware.com/support/pubs.
Getting Started with vSphere Command-Line Interfaces You can find the most up-to-date technical documentation on the VMware Web site at: http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: docfeedback@vmware.com Copyright © 2007–2017 VMware, Inc. All rights reserved. Copyright and trademark information. VMware, Inc. 3401 Hillview Ave. Palo Alto, CA 94304 www.vmware.com 2 VMware, Inc.
Contents About This Book 5 1 Managing vSphere with Command-Line Interfaces 7 Overview of vSphere Command-Line Interfaces 7 Using ESXCLI for Host Management 10 ESXCLI Syntax 10 Running ESXCLI Commands Installed as Part of vCLI 11 ESXCLI Command Support When Host and vCLI Versions Do Not Match 11 Using PowerCLI to Manage Hosts and Virtual Machines 12 Using DCLI to Manage vCenter Services 12 DCLI Syntax 13 vCLI Package Contents 13 2 Installing vCLI 15 Installation Overview 15 Overview of Linux Installatio
Getting Started with vSphere Command-Line Interfaces 4 Running vCLI Host Management Commands 31 Overview of Running vCLI Host Management Commands 32 Targeting the Host Directly 32 Targeting a Host That is Managed by a vCenter Server System 32 Protecting Passwords 32 Order of Precedence for vCLI Host Management Commands 33 Authenticating Through vCenter Server and vCenter Single Sign-On 34 Authenticating Directly to the Host 34 Create and Use a Session File 34 Using Environment Variables 35 Using a Configu
About This Book Getting Started with vSphere Command‐Line Interfaces gives an overview of command-line interfaces in ® vSphere and gets you started with ESXi Shell commands and vCLI (VMware vSphere Command-Line Interface) commands. This book also includes instructions for installing vCLI and a reference to connection parameters. Intended Audience This book is for experienced Windows or Linux system administrators who are familiar with vSphere administration tasks and data center operations.
Getting Started with vSphere Command-Line Interfaces Background information for the tasks discussed in this book is available in the vSphere documentation set. The vSphere documentation consists of the combined VMware vCenter Server and ESXi documentation. 6 VMware, Inc.
Managing vSphere with CommandLine Interfaces 1 vSphere supports several command-line interfaces for managing your virtual infrastructure including a set of ESXi Shell commands, PowerCLI commands, and DCLI (Datacenter CLI) commands for management of vCenter services. You can run commands locally, from an administration server, or from scripts. You can choose the CLI best suited for your needs, and write scripts to automate your management tasks.
Getting Started with vSphere Command-Line Interfaces Figure 1‑1. vSphere CLIs for Host and vCenter Services Management Linux vSphere Management Assistant Windows vCLI vicfg-* ESXCLI DCLI Others (esxtop, vimcmd, vsish, rvc...) PowerCLI API vCenter Server DCLI API API ESXi ESXi ESXCLI esxcfg-* ESXCLI esxcfg-* The following command sets are available. For more information about each command set, see the referenced documentation. 8 VMware, Inc.
Chapter 1 Managing vSphere with Command-Line Interfaces Command Set Description See ESXCLI commands Manage many aspects of an ESXi host. You can run ESXCLI commands remotely or in the ESXi Shell. n vCLI package - Install the vCLI package on the server of your choice, or deploy a vSphere Management Assistant (vMA) virtual machine and target the ESXi system that you want to manipulate. You can run ESXCLI commands against a vCenter Server system and target the host indirectly.
Getting Started with vSphere Command-Line Interfaces Command Set Description localcli commands Set of commands for use with VMware Technical Support. localcli commands are equivalent to ESXCLI commands, but bypass the host daemon (hostd) . The localcli commands are only for situations when hostd is unavailable and cannot be restarted. After you run a localcli command, you must restart hostd. Run ESXCLI commands after the restart.
Chapter 1 Managing vSphere with Command-Line Interfaces Syntax Element command Description Reports on or modifies the state of the system. The following examples show how you can use this element. esxcli --server myESXi --username user1 --password 'my_password' storage nfs list esxcli --server myVCServer --username user1 --password 'my_pwd' --vihost myESXi.mycompany.com storage nfs list options Many commands support one or more of the options displayed in the help or the vCLI reference.
Getting Started with vSphere Command-Line Interfaces Using PowerCLI to Manage Hosts and Virtual Machines VMware PowerCLI contains snap-ins and modules based on Microsoft PowerShell for automating vSphere and vCloud Director administration. PowerCLI provides C# and PowerShell interfaces for vSphere and other VMware product administration. PowerCLI is based on Microsoft PowerShell and uses the PowerShell basic syntax and concepts.
Chapter 1 Managing vSphere with Command-Line Interfaces DCLI Syntax Each DCLI command uses the same syntax. The command name can be followed by DCLI connection and formatting options, each preceded by a plus (+) sign. You also specify the namespace, the command, and the command options. Namespaces are nested. Note The order in which DCLI options are provided on the command line is not important. However, you must specify DCLI options with a plus (+) and command-specific options with a minus (-).
Getting Started with vSphere Command-Line Interfaces You can run vCLI commands from a Windows or Linux system, or use vMA. n Install the vCLI command set on the Windows or Linux system from which you want to administer your ESXi systems and run vCLI commands. See Chapter 2, “Installing vCLI,” on page 15. n Deploy a vMA virtual machine to an ESXi system and run vCLI commands from there. After you have installed the vCLI package, you can run the host management commands in the set against ESXi hosts.
Installing vCLI 2 You can install a vCLI package on a Linux or a Microsoft Windows system, or use vCLI as part of the vSphere Management Assistant that can be deployed on an ESXi host.
Getting Started with vSphere Command-Line Interfaces The vCLI installer installs both vSphere SDK for Perl and vCLI because many vCLI commands run on top of the vSphere SDK for Perl. The content of the installer package differs for different platforms. Platform Installation Process Windows You must install required software. The installation package includes vCLI and vSphere SDK for Perl. Red Hat Enterprise Linux You must install required software.
Chapter 2 Installing vCLI 2 If the required software is found, the installer proceeds. Otherwise, the installer stops and informs you that you must install the software. See “Installing Required Prerequisite Software for Red Hat Enterprise Linux,” on page 19 and “Installing Prerequisite Software for Linux Systems with Internet Access,” on page 20 for instructions. 3 The installer checks whether the following Perl modules are found, and whether the correct version is installed. VMware, Inc.
Getting Started with vSphere Command-Line Interfaces Earlier versions of libwww-perl include the LWP-Protocol-https module. More recent versions of libwww-perl do not include the LWP-Protocol-https module and you must install that module. Note If you intend to run vCLI commands with SSL certification, verify that LWP::UserAgent 6.00 or later is installed. The installer does not check this module, and earlier versions do not work with SSL. 4 The installer proceeds depending on the Linux distribution.
Chapter 2 Installing vCLI Installing Required Prerequisite Software for Red Hat Enterprise Linux Prerequisite software on RHEL includes required software and recommended Perl modules. Required Software If required software is not installed, the vCLI installer stops. You can install the prerequisite software by using yum, the RHEL package installer, or from the installation DVD, as follows. Platform Installation RHEL 6.6 64-bit yum install e2fsprogs-devel libuuid-devel yum install glibc.
Getting Started with vSphere Command-Line Interfaces Procedure 1 Untar the vCLI binary that you downloaded. tar –zxvf VMware-vSphere-CLI-6.X.X-XXXXX.XXXX.x86_64.tar.gz A vmware-vsphere-vcli-distrib directory is created. 2 Log in as superuser and run the installer. //sudo vmware-vsphere-cli-distrib/vmware-install.pl 3 To accept the license terms, enter yes and press Enter. 4 To install Perl modules locally, enter yes and press Enter.
Chapter 2 Installing vCLI Platform Installation RHEL 6.6 64-bit Find the required modules on the installation DVD, or use yum to install them. yum install e2fsprogs-devel libuuid-devel yum install glibc.i686 yum install perl-XML-LibXML RHEL 7.1 64-bit Find the required modules on the installation DVD, or use yum to install them. yum install e2fsprogs-devel libuuid-devel openssl-devel perl-devel yum install glibc.i686 zlib.i686 yum install perl-XML-LibXML libncurses.so.
Getting Started with vSphere Command-Line Interfaces Install the vCLI Package on a Linux System with Internet Access You can install the vCLI package and run a command to verify that installation was successful. Prerequisites Verify that you have installed the required prerequisite software. Procedure 1 Log in as root. 2 Untar the vCLI binary that you downloaded. tar –zxvf VMware-vSphere-CLI-6.X.X-XXXXX.i386.tar.gz A vmware-vsphere-vcli-distrib directory is created.
Chapter 2 Installing vCLI Uninstall the vCLI Package on Linux You can use a script included in the installation to uninstall the vCLI package. Procedure 1 Navigate to the directory where you installed vCLI. The default directory is /usr/bin. 2 Run the vmware-uninstall-vSphere-CLI.pl script. The command uninstalls vCLI and the vSphere SDK for Perl.
Getting Started with vSphere Command-Line Interfaces Uninstall the vCLI Package on Windows You can uninstall the vCLI package by following the standard Windows procedure. Procedure 1 Find the option for adding and removing programs on the Windows operating system that you are using. 2 In the panel that appears, select VMware vSphere CLI and click Remove. 3 Click Yes when prompted. The system uninstalls vCLI and vSphere SDK for Perl.
Running Host Management Commands in the ESXi Shell 3 Usually, installing vCLI and running commands from a remote system, with one or more hosts as targets, is recommended. However, for maintenance and troubleshooting tasks you might prefer to run ESXCLI commands in the ESXi Shell or connect to the ESXi Shell with SSH. To run commands, you must first establish access to the ESXi Shell.
Getting Started with vSphere Command-Line Interfaces Enabling Local ESXi Shell Access You can enable the ESXi Shell from the direct console or the vSphere Web Client. Enable the ESXi Shell in the Direct Console If you have access to the Direct Console Interface, you can enable the ESXi Shell from there. Procedure 1 At the direct console of the ESXi host, press F2 and provide credentials when prompted. 2 Scroll to Troubleshooting Options and press Enter. 3 Select Enable ESXi Shell and press Enter.
Chapter 3 Running Host Management Commands in the ESXi Shell Use the Local ESXi Shell After you enable the ESXi Shell in the direct console, you can use it from the main direct console screen or remotely through a serial port. Procedure 1 At the main direct console screen, press Alt-F1 to open a virtual console window to the host. 2 Provide credentials when prompted. When you enter the password, characters are not displayed on the console. 3 Enter shell commands to perform management tasks.
Getting Started with vSphere Command-Line Interfaces 3 In the Services section, click Edit. 4 Select SSH. 5 n To temporarily start or stop the service, click the Start or Stop button. n To change the Startup policy across reboots, select Start and stop with host and reboot the host. Click OK. What to do next After you have enabled SSH, you can log in to the ESXi Shell remotely and run ESXi Shell commands.
Chapter 3 Running Host Management Commands in the ESXi Shell Prerequisites Verify that the ESXi Shell is enabled. Procedure 1 Log in to the shell. 2 Run the command. For example, to list NFS storage devices, run the following command. esxcli storage nfs list What to do next You can use --help at any level of esxcli for help on available namespaces, commands, or options. VMware, Inc.
Getting Started with vSphere Command-Line Interfaces 30 VMware, Inc.
Running vCLI Host Management Commands 4 You can run vSphere Command-Line Interface (vCLI) host management commands from the command line of the system where you installed the package, from the vMA command line, and from scripts. Host management commands, which include ESXCLI and vicfg- commands, require at a minimum access to the target server to run the commands on. Users must authenticate to the host, and can only perform tasks that they are authorized to perform.
Getting Started with vSphere Command-Line Interfaces Overview of Running vCLI Host Management Commands You can run vCLI commands interactively or in scripts, and you can target the host directly or target a vCenter Server system that manages the host. Targeting the Host Directly You can target the host directly from an administration server on which you installed vCLI, by using vMA, or by running scripts. n Open a command prompt on a Linux or Windows system on which you installed vCLI.
Chapter 4 Running vCLI Host Management Commands n Target a vCenter Server system and authenticate to vCenter Single Sign-On. You can save the corresponding session and use it for subsequent connections. See “Authenticating Through vCenter Server and vCenter Single Sign-On,” on page 34. n Use variables or configuration files. n If you are running vCLI on a Windows system, you can use the --passthroughauth option.
Getting Started with vSphere Command-Line Interfaces Authenticating Through vCenter Server and vCenter Single Sign-On For all ESXi hosts that are managed by a vCenter Server system that is integrated with vCenter Single SignOn 6.0 and later, you can authenticate directly to the vCenter Server system, or you can authorize to vCenter Server through vCenter Single Sign-On. The best practice is to authenticate through vCenter Single Sign-On.
Chapter 4 Running vCLI Host Management Commands 2 Operating System Command Windows cd C:\Program Files\VMware\VMware vSphere CLI\Perl\apps\session Linux cd /usr/share/lib/vmware-vcli/apps/session Run save_session. You can use the save_session.pl script or the --savesessionfile option to the vCLI command. You must specify the server which to connect to and the name of a session file in which the script saves an authentication cookie.
Getting Started with vSphere Command-Line Interfaces Using a Configuration File You can use a text file that contains variable names and settings as a configuration file. Variables corresponding to the options are shown in “Common Options for vCLI Host Management Command Execution,” on page 40. Caution Limit read access to a configuration file that contains user credentials. Pass in the configuration file when you run vCLI commands, by using the following syntax.
Chapter 4 Running vCLI Host Management Commands Example: Linux esxcli --server --username snow\-white --password dwarf\$ network ip interface list esxcli --server --username snow\-white --password 'dwarf$' network ip interface list vicfg-mpath --server --username snow\-white --password dwarf\$ --list vicfg-mpath --server --username 'snow-white' --password 'dwarf$' --list Example: Windows esxcli --server
Getting Started with vSphere Command-Line Interfaces vCLI and Lockdown Mode Lockdown mode can disable all direct root access to ESXi machines. To make changes to ESXi systems in lockdown mode you must go through a vCenter Server system that manages the ESXi system. You can use the vSphere Web Client or vCLI commands that support the -vihost option. The following commands cannot run against vCenter Server systems and are therefore not available in lockdown mode.
Chapter 4 Running vCLI Host Management Commands Using the --cacertsfile Option Using a certificate to establish the trust relationship is the most secure option. You can specify the certificate with the --cacertsfile parameter or the VI_CACERTFILE variable. Using the --thumbprint Option You can supply the thumbprint for the target ESXi host or vCenter Server system in the --thumbprint parameter or the VI_THUMBPRINT variable.
Getting Started with vSphere Command-Line Interfaces Common Options for vCLI Host Management Command Execution You can use connection options that are available for all vCLI host management commands and common options that you can use when you run a vicfg- vCLI command. vCLI Connection Options The following table lists options that are available for all vCLI host management commands in alphabetical order. The table includes options for use on the command line and variables for use in configuration files.
Chapter 4 Running vCLI Host Management Commands Option and Environment Variable Description --password VI_PASSWORD= n Uses the specified password (used with --username) to log in to the server. If --server specifies a vCenter Server system, the user name and password apply to that server. If you can log in to the vCenter Server system, you need no additional authentication to run commands on the ESXi hosts that server manages.
Getting Started with vSphere Command-Line Interfaces Option and Environment Variable Description --username VI_USERNAME= Uses the specified user name. n If --server specifies a vCenter Server system, the user name and password apply to that server. If you can log in to the vCenter Server system, you need no additional authentication to run commands on the ESXi hosts that server manages. If --server specifies an ESXi system, the user name and password apply to that system.
Chapter 4 Running vCLI Host Management Commands esxcli --config ${VI_CONFIG_FILE} storage nfs add --host ${VIHOST} --share -volume-name esxcli --config ${VI_CONFIG_FILE} storage nfs list done Run Host Management Commands from a Windows System After you install vCLI and reboot your system, you can test the installation by running a vCLI or SDK for Perl command from the Windows command prompt.
Getting Started with vSphere Command-Line Interfaces 44 VMware, Inc.
Running DCLI Commands 5 You can run DCLI commands as vCLI commands, from the vCenter Server Appliance shell, and from the command prompt of a vCenter Server Windows installation. Important Authentication options for DCLI commands differ from options for vCLI host management commands. Users who run DCLI commands to monitor and manage vCenter services must have the appropriate privileges.
Getting Started with vSphere Command-Line Interfaces n Prepare scripts that contain DCLI commands. Then run the scripts as vCLI scripts, from the vCenter Server Windows command prompt, or from the vCenter Server Appliance shell. Use the credential store options to authenticate. Passwords are not supported in scripts. DCLI Syntax Each DCLI command uses the same syntax. The command name can be followed by DCLI connection and formatting options, each preceded by a plus (+) sign.
Chapter 5 Running DCLI Commands The following table describes the DCLI options. Option Description Default server The vCenter Server system to which DCLI connects. localhost interactive Runs DCLI in interactive shell mode, which supports tab completion of commands, options, and some option values. It also supports saving the command history across DCLI sessions. Interactive mode is faster because DCLI caches the list of commands available on a vCenter Server system.
Getting Started with vSphere Command-Line Interfaces Option Description credstoreremove Removes an entry from the DCLI credential store file. This option removes the entry for a specified server IP address and user name if only one session manager is present for a target server and user. In rare cases, information about multiple session manager entries is present. You must provide the session manager with the session-manager option.
Chapter 5 Running DCLI Commands You must specify a server, user name, and password. If you specify credstore-add, DCLI creates a credential store file on the local machine. As a result, you are no longer required to specify the user name and password when you run DCLI commands again. Running DCLI Commands on the vCenter Server Appliance The root user on the vCenter Server Appliance can run DCLI commands from the appliance shell. The following options are available.
Getting Started with vSphere Command-Line Interfaces Authentication Description Command line The user name and password specified on the command line take precedence, even if a credential store exists. Environment variable A user name specified in an environment variable takes precedence over user names in the credential store, but not over the command line. Credential store The user name and password retrieved from the credential store.
Chapter 5 Running DCLI Commands Interactive mode is also a quicker way to browse various namespaces and commands, as DCLI caches the list of namespaces and commands available on the server for faster access. DCLI interactive mode provides specific shell commands which can be accessed by running dcli> help. You can change the prompt for DCLI interactive mode by using dcli +interactive +prompt when entering interactive mode. DCLI SSL Connection DCLI uses a secure connection by default.
Getting Started with vSphere Command-Line Interfaces 52 VMware, Inc.
Index D DCL input 50 output 50 return codes 50 DCLI authentication 49 credential store file 49 history file 51 interactive mode 50 managing vCenter services 12 run commands 45 running commands on the vCenter Server Appliance 49 running vCLI package commands 48 security 51 variables 50 DCLI commands help information 48 usage 48 DCLI options 46 DCLI Syntax 13, 46 E enable certificate verification 24 environment variables usage, vCLI host management commands 35 ESXCLI command support on different versions 11
Getting Started with vSphere Command-Line Interfaces credential store usage 39 direct host authentication 34 direct host targeting 32 lockdown mode 38 managed host targeting 32 order of precedence 33 overview 32 password protection 32 running on Linux 43 running on Windows 43 scripts 42 session file creation 34 session file usage 34 thumbprint usage 39 vCenter Server authentication 34 vCenter Server certificate installation 38 vCenter Single Sign-On authentication 34 Windows SSPI usage 37 vMA, deployment 2