Getting Started With VSphere Command Line Interfaces ESXi 6.7 Vcenter Server 67 Interface Guide

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 59

DownloadGetting Started With VSphere Command-Line Interfaces - ESXi 6.7 Vsphere-esxi-vcenter-server-67-command-line-interface-getting-started-guide
Open PDF In BrowserView PDF
Getting Started with
vSphere Command-Line
Interfaces
17 APR 2018
ESXi 6.7
vCenter Server 6.7

Getting Started with vSphere Command-Line Interfaces

You can find the most up-to-date technical documentation on the VMware website at:
https://docs.vmware.com/
If you have comments about this documentation, submit your feedback to
docfeedback@vmware.com

VMware, Inc.
3401 Hillview Ave.
Palo Alto, CA 94304
www.vmware.com
Copyright © 2007–2018 VMware, Inc. All rights reserved. Copyright and trademark information.
VMware, Inc.

2

Contents
About This Book

6

1 Managing vSphere with Command-Line Interfaces 8
Overview of vSphere Command-Line Interfaces
Using ESXCLI for Host Management
ESXCLI Syntax

8

11

11

Running ESXCLI Commands Installed as Part of vCLI

12

ESXCLI Command Support When Host and vCLI Versions Do Not Match
Using PowerCLI to Manage Hosts and Virtual Machines
Using DCLI to Manage vCenter Services
DCLI Syntax

12

13

13

14

vCLI Package Contents

15

2 Installing vCLI 16
Installation Overview

16

Overview of Linux Installation Process

16

Installing and Uninstalling vCLI on Linux Systems

18

Installing Prerequisite Software for Linux Systems
Install the vCLI Package on a Linux System
Uninstall the vCLI Package on Linux

21

22

Installing and Uninstalling vCLI on Windows
Install the vCLI Package on Windows

22

22

Uninstall the vCLI Package on Windows
Enabling Certificate Verification

19

23

23

3 Running Host Management Commands in the ESXi Shell 24
ESXi Shell Access with the Direct Console
Enabling Local ESXi Shell Access
ESXi Shell Timeout

25

26

Use the Local ESXi Shell

26

Remote ESXi Shell Access with SSH

26

Enable SSH Access in the Direct Console

26

Enable SSH from the vSphere Web Client

27

Access the Remote ESXi Shell with SSH
Lockdown Mode

27

28

Run an ESXCLI Command in the ESXi Shell

VMware, Inc.

24

28

3

Getting Started with vSphere Command-Line Interfaces

4 Running vCLI Host Management Commands 30
Overview of Running vCLI Host Management Commands
Targeting the Host Directly

30

31

Targeting a Host That is Managed by a vCenter Server System
Protecting Passwords

31

31

Order of Precedence for vCLI Host Management Commands

32

Authenticating Through vCenter Server and vCenter Single Sign-On
Authenticating Directly to the Host

33

Create and Use a Session File

34

Using Environment Variables
Using a Configuration File

35

35

Using Command-Line Options

36

Using the Microsoft Windows Security Support Provider Interface
vCLI and Lockdown Mode

37

37

Trust Relationship Requirement for ESXCLI Commands
Download and Install the vCenter Server Certificate
Using the --cacertsfile Option

39

Using the --thumbprint Option

39

Use the Credential Store

33

38
38

39

Common Options for vCLI Host Management Command Execution
Using vCLI Commands in Scripts

40

42

Run Host Management Commands from a Windows System
Run Host Management Commands from a Linux System

43

43

5 Running DCLI Commands 45
Overview of Running DCLI Commands
DCLI Syntax

46

46

DCLI Options

47

Run DCLI Commands in Interactive Mode

49

Run DCLI Commands in Non-Interactive Mode
Using DCLI Commands

50

50

Displaying Help Information for DCLI Commands

51

Running DCLI Commands Included in the vCLI Package

51

Running DCLI Commands on the vCenter Server Appliance
DCLI Authentication

52

52

VMware Cloud on AWS Authentication
vCenter Server Authentication

52

53

Using DCLI with a Credential Store File

54

Order of Precedence for DCLI Authentication to vCenter Server
Using the DCLI Configuration Store
DCLI Modules

56

Internal DCLI Commands

VMware, Inc.

54

55

56

4

Getting Started with vSphere Command-Line Interfaces

Using Default Options

56

Input, Output, and Return Codes
Using DCLI with Variables
DCLI Security

57

58

SSL Communication
DCLI Secret Input
DCLI History File

58

58

Setting the DCLI Log File

VMware, Inc.

57

59

59

5

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.

VMware Technical Publications Glossary
VMware Technical Publications provides a glossary of terms that might be unfamiliar to you. For
definitions of terms as they are used in VMware technical documentation, go to
http://www.vmware.com/support/pubs.

Related Documentation
The documentation for vCLI is available on the VMware {code} vSphere CLI page. Go to
https://code.vmware.com/web/dp/tool/vsphere-cli.
n

vSphere Command-Line Interface Concepts and Examples presents usage examples for many host
management commands, and explains how to set up software and hardware iSCSI, add virtual
switches, place hosts in maintenance mode, and so on. The document includes the same example
with the ESXCLI command and with the vicfg- command.

n

vSphere Command-Line Interface Reference is a reference to both ESXCLI commands and vicfgcommands. The vicfg- command help is generated from the POD available for each command, run
pod2html for any vicfg- command to generate individual HTML files interactively. The ESXCLI
reference information is generated from the ESXCLI help.

n

DCLI Reference is a reference to DCLI commands for managing vCenter services.

The documentation for PowerCLI is available on the VMware {code} PowerCLI page.
The vSphere SDK for Perl documentation explains how you can use the vSphere SDK for Perl and
related utility applications to manage your vSphere environment.

VMware, Inc.

6

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.

VMware, Inc.

7

Managing vSphere with
Command-Line Interfaces

1

vSphere supports several command-line interfaces for managing your virtual infrastructure including a set
of ESXi Shell commands, PowerCLI commands, and DCLI (Data Center 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.
This chapter includes the following topics:
n
Overview of vSphere Command-Line Interfaces
n

Using ESXCLI for Host Management

n

Using PowerCLI to Manage Hosts and Virtual Machines

n

Using DCLI to Manage vCenter Services

n

vCLI Package Contents

Overview of vSphere Command-Line Interfaces
vSphere includes commands for managing different aspects of your environment.
The following CLIs are available for managing hosts, either directly or through the vCenter Server system
that manages the host. You can also manage vCenter services by using DCLI.

VMware, Inc.

8

Getting Started with vSphere Command-Line Interfaces

Figure 1‑1. vSphere CLIs for Host and vCenter Services Management
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.
Command Set

Description

See

ESXCLI
commands

Manage many aspects of an ESXi host. You can run ESXCLI commands remotely
or in the ESXi Shell.

Using ESXCLI for Host
Management

n

n

vCLI package - Install the vCLI package on the server of your choice. You can
run ESXCLI commands against a vCenter Server system and target the host

Chapter 2 Installing vCLI

indirectly. Running against vCenter Server systems by using the -vihost

Concepts and Examples

parameter is required if the host is in lockdown mode.

vSphere Command-Line
Interface Reference

ESXi Shell - Run ESXCLI commands in the local ESXi Shell to manage that
host.

vSphere Command-Line

You can also run ESXCLI commands from the VMware PowerCLI prompt by using
the Get-EsxCli cmdlet.
vicfg- and other
vCLI commands

Users can manage hosts remotely. Install the vCLI package on a Windows or Linux
system, and target the ESXi system that you want to manipulate.
vicfg- commands are included in this release but are deprecated. Migrate to
ESXCLI where possible.
You can run the commands against ESXi systems or against a vCenter Server
system. If you target a vCenter Server system, use the --vihost option to specify

Chapter 2 Installing vCLI
vSphere Command-Line
Concepts and Examples
vSphere Command-Line
Interface Reference

the target ESXi system.
Note If the ESXi system is in strict lockdown mode, you must run commands
against the vCenter Server system that manages your ESXi system.

VMware, Inc.

9

Getting Started with vSphere Command-Line Interfaces

Command Set

Description

See

esxcfg-

Available in the ESXi Shell. esxcfg- commands are included in this release but

commands

are deprecated. Migrate to ESXCLI where possible.

Command-Line
Management of vSphere
5 and vSphere 6 for
Service Console Users

DCLI commands

Manage VMware SDDC services.
DCLI is a CLI client to the vSphere Automation SDK interface for managing
VMware SDDC services. A DCLI command talks to a vSphere Automation API
endpoint to locate relevant information, and then runs the command and displays
the result to the user.
You can run DCLI commands as follows.

VMware
PowerCLI
cmdlets

n

vCenter Server Appliance - Run DCLI commands from the
vCenter Server Appliance shell. See Running DCLI Commands on the vCenter
Server Appliance.

n

vCenter Server Windows command prompt - Install vCenter Server on a
supported Windows system and run DCLI commands from the command
prompt.

n

vCLI package - Open a command prompt on a Linux or Windows system on
which you installed vCLI. Enter commands into that command prompt,
specifying connection options. See Chapter 5 Running DCLI Commands.

n

Prepare scripts that include DCLI commands and run the scripts as vCLI
scripts from the vCenter Server Windows command prompt or from the
vCenter Server Appliance shell.

VMware PowerCLI provides a Windows PowerShell interface to the vSphere API.
PowerCLI includes PowerShell cmdlets for administering vSphere components.

Chapter 5 Running DCLI
Commands
See the vSphere
Automation SDK
documentation for
information about
supported services and
how they interact.

VMware PowerCLI
documentation

PowerCLI includes more than 600 cmdlets, a set of sample scripts, and a function
library for management and automation. The vSphere Image Builder PowerCLI
and vSphere Auto Deploy PowerCLI modules are included when you install
PowerCLI.

localcli

Set of commands for use with VMware Technical Support. localcli commands

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.
Important If you use a localcli command, an inconsistent system state and
potential failure might result.

pktcap-uw utility

Enables you to monitor the traffic that flows through the physical network adapters,
the VMkernel adapters, and the virtual machine adapters, and to analyze the
packet information by using conventional network analysis tools such as
Wireshark.

vSphere Networking
documentation

dir-cli

Commands for managing the vCenter Single Sign-On and certificate infrastructure.

vSphere Security
documentation

Enables you to configure and troubleshoot the vCenter Server Appliance and to
monitor the processes and services running in the appliance.

vCenter Server
Appliance Configuration
documentation

vecs-cli
certool
appliancesh

VMware, Inc.

10

Getting Started with vSphere Command-Line Interfaces

Using ESXCLI for Host Management
You can manage many aspects of an ESXi host by using commands from the ESXCLI command set. You
can run ESXCLI commands as vCLI commands, or run them in the ESXi Shell in troubleshooting
situations.
You can also run ESXCLI commands from the PowerCLI shell by using the Get-EsxCli cmdlet. See the
PowerCLI User's Guide and the PowerCLI Cmdlet Reference.
The set of ESXCLI commands that are available on a host depends on the host configuration. The
vSphere Command-Line Interface Reference lists help information for all ESXCLI commands. You can
run esxcli --server  --help before you run a command on a host to make sure that the
command is defined on the host that you are targeting.

ESXCLI Syntax
Each ESXCLI command uses the same syntax.
The following is the standard syntax structure of an ESXCLI command.
esxcli [dispatcher options]  [ ...]  [cmd options]

Syntax
Element
dispatcher
options

Description
Predefined options for connection information such as target host, user name, and so on. See Chapter 4 Running
vCLI Host Management Commands. Not required when you run the command in the ESXi Shell. If the target
server is a vCenter Server system, specify the target ESXi host before any ESXCLI namespaces, commands,
and supported options.
Many ESXCLI commands generate output that you might want to use in your application. You can run esxcli
with the --formatter dispatcher option and send the resulting output as input to a parser.
Important Starting with vSphere 6.0, ESXCLI expects a trust relationship between the target host and the
system on which you run the command. You can establish this relationship in one of these ways:
n

Use the --cacertsfile option or VI_CACERTFILE variable.

n

Store the thumbprint in the session file.

n

Specify the thumbprint with the --thumbprint option or VI_THUMBPRINT variable.

You can pass in the thumbprint that is returned in the error if you trust the host that you are targeting. See Trust
Relationship Requirement for ESXCLI Commands for an example.
namespace

VMware, Inc.

Groups ESXCLI commands. vSphere 5.0 and later support nested namespaces.

11

Getting Started with vSphere Command-Line Interfaces

Syntax
Element

Description

command

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. For some
commands, multiple option values, separated by spaces, are possible.
The following example shows how you can use this element.
esxcli system module parameters set -m  -p "a=1 b=1 c=1"

Running ESXCLI Commands Installed as Part of vCLI
You can run an ESXCLI command, installed as part of vCLI, in the ESXi Shell for troubleshooting
purposes and remotely against a specific host or against a vCenter Server system.
You can install the vCLI package on one of the supported Windows or Linux systems. The ESXCLI
command set is included. Specify connection options to run commands against an ESXi host directly, or
target a vCenter Server system and specify the ESXi host to run the command against. See Chapter 2
Installing vCLI.
Note Starting with vSphere 6.0, a trust relationship must exist between the host from which you run
ESXCLI commands and the target ESXi host or vCenter Server system. See Trust Relationship
Requirement for ESXCLI Commands.
See Chapter 4 Running vCLI Host Management Commands.

ESXCLI Command Support When Host and vCLI Versions Do Not
Match
When you run an ESXCLI vCLI command, you must know the commands that are supported on the
target host specified with --server.
The following examples demonstrate command support when versions do not match.
n

If you run commands against ESXi 5.0 hosts, ESXCLI 5.0 commands are supported. ESXCLI 5.1
commands that were included in ESXCLI 5.0 are also supported.

n

If you run commands against ESXi 5.1 hosts, ESXCLI 5.1 and ESXCLI 5.0 commands are supported.

n

If you run commands against ESXi 6.x hosts, ESXCLI 6.x commands are supported.

VMware, Inc.

12

Getting Started with vSphere Command-Line Interfaces

VMware partners might develop custom ESXCLI commands that you can run on hosts where the partner
VIB is installed.
Run esxcli --server  --help for a list of namespaces supported on the target. You can
explore the namespaces for additional help.

Using PowerCLI to Manage Hosts and Virtual Machines
VMware PowerCLI contains 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.
Microsoft PowerShell is both a command-line and scripting environment. It uses the .NET object model
and provides administrators with system administration and automation capabilities. To work with
PowerShell, you run commands, which are called cmdlets.
PowerShell supports features such as pipelines, wildcards, and easy access to command-line help.
You can use ESXCLI commands from the PowerCLI console, by using the following options.
n

Through the cmdlet that provides direct access to the ESXCLI namespaces, applications, and
commands.

n

Through .NET methods, which you use to create managed objects that correspond to specific
ESXCLI applications. To access the ESXCLI, you can call methods on these managed objects.

See the PowerCLI User’s Guide on VMware {code}.

Using DCLI to Manage vCenter Services
With the DCLI command set, you can run virtual machine management, appliance management, content
library, and tagging commands.
You cannot manage services that are part of vSphere 5.5 or earlier from DCLI. DCLI is not a host
management CLI.
DCLI is a CLI client of the vSphere Automation SDK. The following workflow explains how DCLI works.
1

You run a DCLI command.

2

If you are not authenticated, DCLI prompts for a user name and password.

3

The command connects you to the vCenter Single Sign-On service and checks whether the user
account specified on the command line or in a credential store file can authenticate.

4

If you can authenticate, DCLI communicates with the vCenter Server and runs the
vSphere Automation API that corresponds to the DCLI command. Different vCenter Server systems
support different services.
Note If the authenticated user account does not have permissions to run the DCLI command, you
receive an Unauthorized error message, even if the user credentials are correct.

VMware, Inc.

13

Getting Started with vSphere Command-Line Interfaces

5

DCLI displays the result or an error message.

You can run DCLI commands as follows.
n

vCLI package - Install the vCLI package on the server of your choice. You can then run DCLI
commands against an endpoint. See Using DCLI Commands.

n

vCenter Server Appliance - Run DCLI commands from the vCenter Server Appliance shell. See
Running DCLI Commands on the vCenter Server Appliance.

n

vCenter Server Windows command prompt - Install vCenter Server on a supported Windows system
and run DCLI commands from the command prompt.

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 two minus signs (--).
The syntax of a DCLI command is the following.
dcli +[DCLI options]  [ ...]  --[cmd option] [option value]

The following table describes the DCLI syntax elements.
Syntax Element

Description

DCLI options

Predefined options for connection information including the vSphere Automation SDK endpoint and formatting
options. Always preceded by a plus (+) sign.
Not required when you run the command in the vCenter Server Appliance shell or from the command prompt
of a vCenter Server Windows installation.

namespace

Groups DCLI commands. Namespaces correspond to the vSphere Automation SDK namespaces and are
nested.

command

Reports on or modifies the state of the system.

option and value

Command option and value pairs preceded by two minus signs (--).

Examples
./dcli +server myvc com vmware vcenter vm list

./dcli com vmware vmc orgs sddcs list --org orgID +vmc-server

Note Under Windows, you can navigate to the directory that contains the DCLI binary and start
commands with dcli instead of ./dcli.

VMware, Inc.

14

Getting Started with vSphere Command-Line Interfaces

vCLI Package Contents
vCLI is not a command set but a package of several command sets.
You usually install vCLI on an administration server and run scripts from there against other hosts or, for
DCLI, against vCenter Server systems or VMware Cloud on AWS. Some vCLI commands can also be run
locally on the ESXi host or the vCenter Server system.
When you install the vCLI package, the following command sets become available.
n

DCLI commands - These commands are available as part of vCLI, from the
vCenter Server Appliance, and from the command-prompt of a vCenter Server Windows installation.

n

Host Management commands - Includes the following command sets.
n

ESXCLI commands - The ESXCLI commands included in the vCLI package are equivalent to the
ESXCLI commands available in the ESXi Shell.

n

vicfg- commands - The vicfg- command set is similar to the deprecated esxcfg- command
set in the ESXi Shell. vicfg- commands are still included in this release but are deprecated.
Migrate to ESXCLI where possible.

n

Miscellaneous commands - A small set of commands for managing and monitoring ESXi hosts,
including vmkfstools and resxtop . In many cases, equivalent but slightly different commands
are available in the ESXi Shell.

Important ESXi Shell is intended for experienced users only. Minor errors in the shell can result in
serious problems. Instead of running commands directly in the ESXi Shell, use vCLI or PowerCLI.
You can 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.
After you have installed the vCLI package, you can run the host management commands in the set
against ESXi hosts. You can run the DCLI commands against a server by specifying the IP address or
host name and can manage the services associated with that server.
You must specify connection parameters when you run a vCLI command. The connection parameters
differ for DCLI commands and for other commands. See Chapter 4 Running vCLI Host Management
Commands and Using DCLI Commands.

VMware, Inc.

15

Installing vCLI

2

You can install a vCLI package on a Linux or a Microsoft Windows system.
This chapter includes the following topics:
n

Installation Overview

n

Overview of Linux Installation Process

n

Installing and Uninstalling vCLI on Linux Systems

n

Installing and Uninstalling vCLI on Windows

n

Enabling Certificate Verification

Installation Overview
You can install a vCLI package on a supported platform.
You can install a vCLI package on a physical or virtual machine. See Installing and Uninstalling vCLI on
Linux Systems and Installing and Uninstalling vCLI on Windows.
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.

Linux

You must install required software and you must have Internet access. See Installing Prerequisite Software for Linux
Systems.
The installer downloads other Perl modules from CPAN.

After installation, you can run vCLI commands and vSphere SDK for Perl utility applications from the
operating system command line. Each time you run a command, you can specify the target server
connection options directly or indirectly. You can also write scripts and manage your vSphere environment
using those scripts.

Overview of Linux Installation Process
The installation script for vCLI is supported on the Linux distributions that are listed in the Release Notes.

VMware, Inc.

16

Getting Started with vSphere Command-Line Interfaces

The vCLI package installer installs the vCLI scripts and the vSphere SDK for Perl. The installation
proceeds as follows.
1

The installer checks whether the following required prerequisite software are installed on the system.
Perl

Perl version 5.8.8 or version 5.10 must be installed on your system.

OpenSSL

The vCLI requires SSL because most connections between the system on which you run the command and the
target vSphere system are encrypted with SSL.
The OpenSSL library (libssl-devel package) is not included in the default Linux distribution. See Installing
Prerequisite Software for Linux Systems.

LibXML2

Used for XML parsing. The vCLI client requires 2.9.6 or later. If you have an older version installed, you must
upgrade to 2.9.6 or later.
The libxml2 package is not included in the default Linux distribution. See Installing Prerequisite Software for
Linux Systems.
Included in uuid-devel for SLES 11 and in e2fsprogs-devel for other Linux platforms. Required by the UUID

uuid

Perl module.

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 Prerequisite Software for Linux Systems for
instructions.

3

The installer checks whether the following Perl modules are found, and whether the correct version is
installed.
n

Crypt-SSLeay-0.72

n

IO-Compress-Zlib-2.037

n

Compress-Raw-Zlib-2.037

n

Archive-Zip-1.28

n

Data-Dumper-2.121

n

XML-LibXML-2.0129

n

libwww-perl-6.15

n

LWP-Protocol-https-6.07

n

XML-LibXML-Common2.0129

n

XML-NamespaceSupport-1.12

n

XML-SAX-0.99

n

UUID-0.27

n

SOAP-Lite-0.710.08

n

HTML-Parser-3.60

n

version-0.78

n

MIME-Base64-3.14

n

Socket6-023

VMware, Inc.

17

Getting Started with vSphere Command-Line Interfaces

n

IO-Socket-INET6-2.71

n

Net-INET6Glue-0.600_1

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 whether the Perl modules are found.
n

If a recommended Perl module is not found at all, the installer installs it using CPAN. You must
meet the installation prerequisites or the installer cannot install the Perl modules and stops. See
Installing and Uninstalling vCLI on Linux Systems.

n

If an earlier version of a recommended module is found, the installer does not install a different
version from CPAN and proceeds with the installation. After completing the installation, the
installer displays a message that the version on the system does not match the recommended
version, and recommends that you install the version vCLI was tested with. You can install the
modules by using the package installer for your platform, the installation CD, or CPAN.

n

If a later version of a recommended module is found, the installer proceeds with the installation
and does not display a message after the installation.

Note The installer does not overwrite existing versions of recommended Perl modules. You must
update those modules manually.
5

After all required software and all prerequisite Perl modules are installed, you can install vCLI. See
Installing Prerequisite Software for Linux Systems.

If a previous version of vCLI, Remote CLI, or vSphere SDK for Perl is installed on your system, and you
install vCLI in a different directory, you must reset the PATH environment variable. You can reset the
variable, before or after the installation, by using the command appropriate for your distribution and shell,
for example setenv or export. If you do not reset the path, the system might still look for executable files
in the old location.

Installing and Uninstalling vCLI on Linux Systems
Before you can install the vCLI package on a Linux system, that system must meet specific prerequisites.
n

Internet access - You must have Internet access when you run the installer because the installer uses
CPAN to install prerequisite Perl modules.

n

Development Tools and Libraries - You must install the Development Tools and Libraries for the Linux
platform that you are working with before you install vCLI and prerequisite Perl modules.

VMware, Inc.

18

Getting Started with vSphere Command-Line Interfaces

n

Proxy settings - If your system is using a proxy for Internet access, you must set the http:// and
ftp:// proxies as follows.
export http_proxy=:port
export ftp_proxy=:port

Installing Prerequisite Software for Linux Systems
If the prerequisite software is not installed, the installer stops and requests that you install it.
Installation of prerequisite software depends on the platform that you are using. See the Release Notes
for the supported versions of each Linux platform.
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.5 perl-Crypt-SSLeay

RHEL 7.3 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.5 perl-Crypt-SSLeay
You might have to install GCC by running yum group install "Development Tools" if there is no compiler
already installed.

SUSE
Enterprise

Install the prerequisite packages from the SLES SDK DVD. When you insert the DVD, it offers to autorun. Cancel
the autorun and use the yast package installer to install OpenSSL or other missing required packages.
n

SLES 11 SP3 64-bit
yast -i openssl-devel libuuid-devel libuuid-devel-32bit

n

SLES 12 64-bit
yast -i openssl-devel libuuid-devel libuuid-devel-32bit e2fsprogs-devel

Some users might be authorized to use the Novell Customer Center and use yast to retrieve missing packages
from there.

VMware, Inc.

19

Getting Started with vSphere Command-Line Interfaces

Platform

Installation

Ubuntu 12.04
64-bit

1

Connect to the Internet.

2

Update the local repository of libraries from a terminal window.
sudo apt-get update

3

Install the required libraries from a terminal window.
sudo apt-get install ia32-libs build-essential gcc uuid uuid-dev perl libssl-dev
perl-doc liburi-perl libxml-libxml-perl libcrypt-ssleay-perl

For Ubuntu 12.04 64-bit, the resxtop and ESXCLI commands do not work if you do not install the 32-bit
compatibility libraries.
Ubuntu 14.04
64-bit

1

Connect to the Internet.

2

Update the local repository of libraries from a terminal window.
sudo apt-get update

3

Install the required libraries from a terminal window.
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 gcc-multilib buildessential gcc uuid uuid-dev perl libssl-dev perl-doc liburi-perl libxml-libxml-perl
libcrypt-ssleay-perl

For Ubuntu 14.04 64-bit, the resxtop and ESXCLI commands do not work if you do not install the 32-bit
compatibility libraries.
Ubuntu 15.10
64-bit

1

Connect to the Internet.

2

Update the local repository of libraries from a terminal window.
sudo apt-get update

3

Install the required libraries from a terminal window.
sudo apt-get install lib32z1 lib32ncurses5 build-essential uuid uuid-dev perl
libssl-dev perl-doc libxml-libxml-perl libcrypt-ssleay-perl libsoap-lite-perl

For Ubuntu 15.10 64-bit, the resxtop and ESXCLI commands do not work if you do not install the 32-bit
compatibility libraries.
Ubuntu 16.04
64-bit

1

Connect to the Internet.

2

Update the local repository of libraries from a terminal window.
sudo apt-get update

3

Install the required libraries from a terminal window.
sudo apt-get install lib32z1 lib32ncurses5 build-essential uuid uuid-dev libssl-dev
perl-doc libxml-libxml-perl libcrypt-ssleay-perl libsoap-lite-perl libmodule-buildperl

For Ubuntu 16.04 64-bit, the resxtop and ESXCLI commands do not work if you do not install the 32-bit
compatibility libraries.

VMware, Inc.

20

Getting Started with vSphere Command-Line Interfaces

Install the vCLI Package on a Linux System
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

Download the vCLI Linux installer package.
You can find the installer in the Automation Tools and SDKs section of the Drivers & Tools tab of
the vSphere download page.

2

Log in as root.

3

Untar the vCLI binary that you downloaded.
tar –zxvf VMware-vSphere-CLI-6.X.X-XXXXX.x86_64.tar.gz

A vmware-vsphere-vcli-distrib directory is created.
4

(Optional) If your server uses a proxy to access the Internet, and if your http:// and ftp:// proxy were
not set when you installed prerequisite software, set them now.
export http_proxy=:port
export ftp_proxy=:port

5

Run the installer.
sudo vmware-vsphere-cli-distrib/vmware-install.pl

6

To accept the license terms, enter yes and press Enter.
The installer connects to CPAN and installs prerequisite software. Establishing a connection might
take a long time.

7

Specify an installation directory, or press Enter to accept the default, which is /usr/bin.
A complete installation process has the following result.
n

A success message appears.

n

The installer lists different version numbers for required modules, if any.

n

The prompt returns to the shell prompt.

If you accepted the defaults during installation, you can find the installed software in the following
locations.
n

vCLI scripts – /usr/bin

n

vSphere SDK for Perl utility applications – /usr/lib/vmware-vcli/apps

VMware, Inc.

21

Getting Started with vSphere Command-Line Interfaces

n

vSphere SDK for Perl sample scripts – /usr/share/doc/vmware-vcli/samples

What to do next

See the vSphere SDK for Perl documentation for a reference to all utility applications. After you install
vCLI, you can test the installation by running a vCLI command or vSphere SDK for Perl utility application
from the command prompt.

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.

Installing and Uninstalling vCLI on Windows
Before you can run vCLI commands from your Windows system, you must install the vCLI package and
test the installation by running a command.

Install the vCLI Package on Windows
The vCLI installation package for Windows installs vSphere SDK for Perl and vSphere CLI, but does not
include the ActivePerl runtime from ActiveState Software.
The vCLI is supported on the Windows platforms that are listed in the Release Notes.
Important If you want to run ESXCLI commands included in vCLI from a Windows system, you must
have the Visual C++ 2008 redistributable for 32-bit installed on that system. Find vcredist_x86.exe for
Visual C++ 2008 and install it on your Windows system.
Prerequisites

Verify that you have ActivePerl or Strawberry Perl version 5.14 or later installed on your Windows system.
Procedure

1

Download the vCLI Windows installer package.
You can find the installer in the Automation Tools and SDKs section of the Drivers & Tools tab of
the vSphere download page.

2

Start the installer.

VMware, Inc.

22

Getting Started with vSphere Command-Line Interfaces

3

(Optional) If prompted to remove older versions of vSphere SDK for Perl or vCLI, you can either
accept or cancel the installation, and install the vCLI package on a different system.
Important The installer replaces both the vSphere SDK for Perl and vCLI. To keep an older version,
install this package on a different system.

4

Click Next in the Welcome page.

5

To install the vCLI in a nondefault directory, click Change and select an alternative directory.
The default location is C:\Program Files\VMware\VMware vSphere CLI.

6

Click Next.

7

Click Install to proceed with the installation.
The installation might take several minutes to complete.

8

Reboot your system.
If you do not reboot, path settings might not be correct on your Windows platform.

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.

Enabling Certificate Verification
You can enable certificate verification by using variables.
The vSphere SDK for Perl and vCLI use Crypt::SSLEay to support certificate verification.
Crypt::SSLEay enables verification of certificates signed by a Certificate Authority (CA) if you set the
following two variables.
n

HTTPS_CA_FILE – The CA file.

n

HTTPS_CA_DIR – The CA directory.

See the Crypt::SSLEay documentation for details on setup.
Caution If the two environment variables HTTPS_CA_FILE and HTTPS_CA_DIR are set incorrectly or if
a problem with the certificate exists, vCLI commands do not complete, and do not display error or warning
messages. Use HTTPS_DEBUG for troubleshooting before running vCLI commands.

VMware, Inc.

23

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.
This chapter includes the following topics:
n

ESXi Shell Access with the Direct Console

n

Remote ESXi Shell Access with SSH

n

Lockdown Mode

n

Run an ESXCLI Command in the ESXi Shell

ESXi Shell Access with the Direct Console
An ESXi system includes a Direct Console User Interface (DCUI) that you can use to start and stop the
system and to perform a limited set of maintenance and troubleshooting tasks.
You can use the direct console to access the ESXi Shell, which is disabled by default. You can enable the
ESXi Shell in the direct console or by using the vSphere Web Client. You can enable local shell access or
remote shell access.
n

With local shell access, you can log in to the shell directly from the Direct Console. See Enabling
Local ESXi Shell Access.

n

With remote shell (SSH) access you can connect to the host by using a shell such as PuTTY, specify
a user name and password, and run commands in the shell. See Remote ESXi Shell Access with
SSH.

The ESXi Shell includes all ESXCLI commands, a set of deprecated esxcfg- commands, and a set of
commands for troubleshooting and remediation.
Important All ESXCLI commands that are available in the ESXi Shell are also included in the vCLI
package.
You can install the vCLI package on a supported Windows or Linux system, and run commands against
your ESXi hosts. Run commands in the ESXi Shell directly or through SSH only in troubleshooting
situations.

VMware, Inc.

24

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.
On the left, Enable ESXi Shell changes to Disable ESXi Shell. On the right, ESXi Shell is Disabled
changes to ESXi Shell is Enabled.

4

Press Esc until you return to the main direct console screen.

What to do next

After you enable the ESXi Shell, you can use it from that monitor or through a serial port.

Enable the ESXi Shell from the vSphere Web Client
If you do not have access to the Direct Console Interface, you can enable the ESXi Shell from the
vSphere Web Client.
Procedure

1

Select the host, click Manage, and keep Settings selected.

2

Click Security Profile.

3

In the Services section, click Edit.

4

Select ESXi Shell.
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.

5

Click OK.

What to do next

After you enable the ESXi Shell, you can use it through a serial port.

VMware, Inc.

25

Getting Started with vSphere Command-Line Interfaces

ESXi Shell Timeout
The ESXi Shell supports a timeout for ESXi Shell availability and a timeout for idle ESXi Shell sessions.
n

Availability timeout - The availability timeout setting is the amount of time that can elapse before you
must log in after the ESXi Shell is enabled. After the timeout period, the service is disabled and users
are not allowed to log in.

n

Idle timeout - If a user enables the ESXi Shell on a host, but forgets to log out of the session, the idle
session remains connected indefinitely.

You can set both timeout values from the Direct Console User Interface or from the vSphere Web Client.
See the vSphere Security document for detailed instructions.

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.

4

To log out, enter exit in the shell.

5

To return to the direct console, press Alt-F2.

What to do next

See the vSphere Installation and Setup documentation for information on serial port setup.

Remote ESXi Shell Access with SSH
If SSH connections are enabled for your ESXi host, you can run shell commands by using a Secure Shell
client such as SSH or PuTTY.

Enable SSH Access in the Direct Console
By default, remote command execution is disabled on an ESXi host, and you cannot log in to the host by
using a remote shell. You can enable remote command execution from the direct console or from the
vSphere Web Client.
Prerequisites
Procedure

1

At the direct console of the ESXi host, press F2 and provide credentials when prompted.

VMware, Inc.

26

Getting Started with vSphere Command-Line Interfaces

2

Scroll to Troubleshooting Options and press Enter.

3

Choose Enable SSH and press Enter.
On the left, Enable SSH changes to Disable SSH. On the right, SSH is Disabled changes to SSH is
Enabled.

4

Press Esc until you return to the main direct console menu.

What to do next

After you have enabled SSH, you can log in to the ESXi Shell remotely and run ESXi Shell commands.

Enable SSH from the vSphere Web Client
By default, remote command execution is disabled on an ESXi host, and you cannot log in to the host by
using a remote shell. You can enable remote command execution from the direct console or from the
vSphere Web Client.
Procedure

1

Select the host, click Manage, and keep Settings selected.

2

Click Security Profile.

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.

Access the Remote ESXi Shell with SSH
If SSH is enabled on your ESXi host, you can run commands on that shell by using an SSH client.
Procedure

1

Open an SSH client.

2

Specify the IP address or domain name of the ESXi host.
Precise directions vary depending on the SSH client that you are using. See vendor documentation
and support.

3

Provide credentials when prompted.

VMware, Inc.

27

Getting Started with vSphere Command-Line Interfaces

Lockdown Mode
To increase the security of your ESXi hosts, you can put them in lockdown mode.
In lockdown mode, all operations must be performed through vCenter Server. By default, only the
vCenter Server system, represented by the vpxuser user, has authentication permissions. No other users
can perform operations against a host in lockdown mode.
vSphere 5.x and later supports normal lockdown mode, as discussed in the vSphere 5.x documentation
center. vSphere 6.0 and later supports more fine-grained management.
n

In normal lockdown mode, you can add users to the DCUI.Access advanced option, which can
access the Direct Console User Interface regardless of their privileges on the host. Starting with
vSphere 6.0, you can also use the vSphere Web Client to add Exception users, which can access the
Direct Console User Interface if they have host management privileges.

n

In strict lockdown mode, users cannot access the Direct Console User Interface. If vCenter Server
becomes unavailable, the host can no longer be managed.

When a host is in normal or strict lockdown mode, you cannot run vSphere CLI commands against the
host directly. Instead, you target the vCenter Server system that manages the host with the --server
option and specify the ESXi host with the --vihost option.
When you enable strict lockdown mode, the Direct Console User Interface service is disabled.
You can enable lockdown mode by using the Add Host wizard to add a host to vCenter Server, by using
the vSphere Web Client to manage a host, or by using the Direct Console User Interface (DCUI).
See the vSphere Security documentation for details on lockdown mode in vSphere 6.x.

Run an ESXCLI Command in the ESXi Shell
You can run ESXCLI commands in the ESXi Shell unless they are marked as internal in the online help.
The ESXi Shell is disabled by default. You must enable the ESXi Shell before you can run commands in
the shell. See ESXi Shell Access with the Direct Console.
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

VMware, Inc.

28

Getting Started with vSphere Command-Line Interfaces

What to do next

You can use --help at any level of esxcli for help on available namespaces, commands, or options.

VMware, Inc.

29

Running vCLI Host Management
Commands

4

You can run vCLI host management commands from the command line of the system where you installed
the package 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.
Note vicfg- commands are deprecated. A deprecation note is displayed when you run these
commands. You can use ESXCLI equivalents of vicfg- commands.
Important If an ESXi system that you target is in lockdown mode, you cannot run vCLI commands
against that system directly. You must target a vCenter Server system that manages the ESXi system and
use the --vihost option to specify the ESXi target. See vCLI and Lockdown Mode.
Note See Chapter 5 Running DCLI Commands for information about DCLI commands, which you can
use to manage vCenter Server services.
This chapter includes the following topics:
n

Overview of Running vCLI Host Management Commands

n

Protecting Passwords

n

Authenticating Through vCenter Server and vCenter Single Sign-On

n

Authenticating Directly to the Host

n

Trust Relationship Requirement for ESXCLI Commands

n

Common Options for vCLI Host Management Command Execution

n

Using vCLI Commands in Scripts

n

Run Host Management Commands from a Windows System

n

Run Host Management Commands from a Linux System

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.

VMware, Inc.

30

Getting Started with vSphere Command-Line Interfaces

Targeting the Host Directly
You can target the host directly from an administration server on which you installed vCLI or by running
scripts.
n

Open a command prompt on a Linux or Windows system on which you installed vCLI. Enter
commands into that command prompt, specifying connection options. See Authenticating Directly to
the Host.

n

Prepare scripts that contain vCLI commands. Then run the scripts from a system that has the vCLI
package installed. See Using vCLI Commands in Scripts.

Note Different command sets in the vCLI package require different connection options.
When you run commands against an ESXi host, you must be authenticated for that host.

Targeting a Host That is Managed by a vCenter Server System
When you target a host that is managed by a vCenter Server system, you can run commands in different
ways.
n

Specify the vCenter Single Sign-On service with the --psc option and, if multiple vCenter Server
systems are associated with the vCenter Single Sign-On service, the vCenter Server system with the
--server option. Specify also the host with the --vihost option.

n

Specify the vCenter Server system with the --server option and the ESXi host with the --vihost
option.

n

Specify only the ESXi host with the --vihost option.

When you can authenticate to a vCenter Single Sign-On service or to a vCenter Server system, you can
target all ESXi hosts that vCenter Server manages without additional authentication. See Authenticating
Through vCenter Server and vCenter Single Sign-On.

Protecting Passwords
You can follow different password protection approaches depending on your environment setup.
Caution If you specify passwords in plain text, you risk exposing the password to other users. The
password might also become exposed in backup files. Do not provide plain-text passwords on production
systems.
Follow one of the following approaches for protecting passwords.
n

If you use a vCLI host management command interactively and do not specify a user name and
password, you are prompted for them. The screen does not echo the password that you enter.

n

For noninteractive use, you can create a session file using the save_session option. See Create and
Use a Session File.

VMware, Inc.

31

Getting Started with vSphere Command-Line Interfaces

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.

n

Use variables or configuration files.

n

If you are running vCLI on a Windows system, you can use the --passthroughauth option. If the
user who runs the command with that option is a known Active Directory user, no password is
required.

With vCLI, you can run scripts against multiple target servers from the same administration server. You
must have the correct privileges to perform the actions on each target, and you must authenticate to the
target.
Important Administrators can place ESXi hosts in lockdown mode for enhanced security. By default,
even the root user cannot run vCLI commands directly against ESXi hosts in lockdown mode. See vCLI
and Lockdown Mode and the vSphere Security documentation.

Order of Precedence for vCLI Host Management Commands
When you run a vCLI host management command, authentication happens in order of precedence.
The order of precedence is described in the following table. This order of precedence always applies.
That means, for example, that you cannot override an environment variable setting in a configuration file.
Note Available options and order of precedence are different for DCLI. See Order of Precedence for
DCLI Authentication to vCenter Server.
If you are authenticating through vCenter Single Sign-On, the order of precedence is preserved. For
example, information you specify on the command line overrides information in an environment variable.
Authentication

Description

See

Command line

Password (--password), session file (--

Create and Use a Session File

sessionfile), or configuration file (-config) specified on the command line.
Environment variable

Password specified in an environment
variable.

Using Environment Variables

Configuration file

Password specified in a configuration
file.

Using a Configuration File

Current account (Active Directory)

Current account information used to
establish an SSPI connection. Available
only on Windows.

Using the Microsoft Windows Security
Support Provider Interface

Credential store

Password retrieved from the credential
store.

vSphere Web Services SDK Programming
Guide and vSphere SDK for Perl
Programming Guide

Prompt the user for a password

Password is not echoed to screen.

VMware, Inc.

32

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
Sign-On 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. The vCenter Single Sign-On service
is included in the Platform Services Controller. The Platform Services Controller can be embedded in your
vCenter Server installation, or one Platform Services Controller can handle authentication, certificate
management, and some other tasks for multiple vCenter Server systems.
Note You cannot use this approach if vCenter Server is integrated with vCenter Single Sign-On 5.0.
You use the --psc option and, optionally, the --server option.
n

psc - Specifies the Platform Services Controller instance associated with the vCenter Server system
that manages the host.

n

server - Specifies the vCenter Server system that manages the host. Required if the Platform
Services Controller instance is associated with more than one vCenter Server system.

n

vihost - Specifies the ESXi host, as in earlier versions of vCLI.

Examples
vicfg-nics -l --username  --password "" --server  --psc
 --vihost 

esxcli --server vc_HOSTNAME_OR_IP> --vihost  --username USERNAME> --password
 --psc  hardware clock get

If the specified user is known to vCenter Single Sign-On, a session is created. You can save the session
with the --savesessionfile argument, and later use that session with the --sessionfile argument.
For example, you can save the session by running the following command.
vicfg-nics -l --username sso_username> --password "" --server vc_HOSTNAME_OR_IP> --psc
 --vihost 

Using a session file results in less overhead and better performance than connecting to the Platform
Services Controller repeatedly.

Authenticating Directly to the Host
vCLI offers several options for authenticating directly to the host.

VMware, Inc.

33

Getting Started with vSphere Command-Line Interfaces

Create and Use a Session File
You can create a session file with the save_session script.
The save_session script is in the /apps/session directory of the vSphere SDK for Perl, which is
included in the vCLI package. You can use the session file, which does not reveal password information,
when you run vCLI commands. If the session file is not used for 30 minutes, it expires.
If you use a session file, other connection options are ignored.
Procedure

1

Navigate to the directory where the script is located.
The following examples show possible locations of the script.

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.
save_session --savesessionfile  --server 

The following examples show the correct syntax for each OS.
Operating System

Command

Windows

save_session.pl --savesessionfile C:\Temp\my_session --server my_server --username
 --password 

Linux

save_session --savesessionfile /tmp/vimsession --server  -username  --password 

Note If you specify a server, but no user name or password, the script prompts you.
3

When you run vCLI commands, pass in the session file using the --sessionfile option.
 --sessionfile  

The following examples show the correct syntax for each OS.

VMware, Inc.

34

Getting Started with vSphere Command-Line Interfaces

Operating System

Command

Windows

esxcli --sessionfile C:\Temp\my_session network ip interface list
vicfg-mpath.pl --sessionfile C:\Temp\my_session --list

Linux

esxcli --sessionfile /tmp/vimsession network ip interface list
vicfg-mpath --sessionfile /tmp/vimsession --list

Using Environment Variables
How you use environment variables depends on the operating system that you are using.
On Linux, you can set environment variables in a Linux bash profile or on the command line by using a
command like the following.
export VI_SERVER=

On Windows, you can set environment variables in the Environment properties dialog box of the System
control panel. For the current session, you can set environment variables at the command line by using a
command like the following.
set VI_SERVER=

Important Do not use escape characters in environment variables.
See Using vCLI Commands in Scripts for an environment variable example.

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

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Author                          : VMware, Inc.
Create Date                     : 2018:04:12 02:01:13-08:00
Modify Date                     : 2018:04:12 02:01:13-08:00
Creator                         : AH XSL Formatter V6.3 MR1 for Windows (x64) : 6.3.2.23978 (2016/03/18 11:26JST)
Producer                        : Antenna House PDF Output Library 6.3.762 (Windows (x64))
Keywords                        : vCLI , ESXCLI , DCLI., command-line., automation
Title                           : Getting Started with vSphere Command-Line Interfaces - ESXi 6.7
Trapped                         : False
Page Count                      : 59
Page Mode                       : UseOutlines
Page Layout                     : SinglePage
Language                        : EN
EXIF Metadata provided by EXIF.tools

Navigation menu