October 18, 2022
How to Install VMware PowerCLI for vSphere Management Automation
PowerCLI is one of the most powerful tools for managing and automating VMware vSphere and vCloud. You can manage VM provisioning, storage, networking, operating systems in hosts and guests, changes, and any other aspect of VMware vSphere. Let’s take a look at what PowerCLI is and the basics of installing this VMware vSphere management tool.
- What Is PowerCLI?
- How to Install the PowerCLI Module Online
- From PowerShell Gallery
- With Chocolatey
- How to Install PowerCLI Offline
- By copying files
- From a ZIP archive
- How to Install VMware PowerCLI in Linux
What Is PowerCLI?
PowerCLI is a set of PowerShell modules from VMware, which extend PowerShell capabilities to understanding additional commands and interacting with VMware environments. When you install PowerCLI, VMware-specific PowerShell commands called commandlets (or cmdlets) are installed, and these allow you to work with VMware vSphere environments.
How to Install PowerCLI Module Online
The latest versions of PowerShell, unlike earlier versions, are distributed as PowerShell modules. There are online and offline methods to install PowerCLI in Windows. Let’s start with online methods for the latest version (currently, v.12.7.0).
Installing PowerCLI from PowerShell Gallery
PowerShell Gallery is the central repository to install content for PowerShell from the internet. PS Gallery contains PowerShell modules, scripts, modules with cmdlets, and other useful data that can be installed quickly and easily.
Note: Hyper-V is uninstalled on the computer on which we will install PowerCLI. This is done to avoid errors because some of the commands used are the same for managing Hyper-V and VMware environments in PowerShell.
Find the PowerCLI module in the PowerShell Gallery repositories:
Find-Module -Name VMware.PowerCLI
NuGet is a package manager for installing software packages, including the ones written for .NET. NuGet is required to install packages from the online PowerShell Gallery, sometimes called the NuGet gallery. If you don’t have NuGet installed yet, install this package manager for PowerShell now.
- To install PowerCLI module for all users, run the command:
Install-Module -Name VMware.PowerCLI
The latest version of PowerCLI is installed by default.
- The command to install PowerCLI only for the current user and without administrative privileges:
Install-Module -Name VMware.PowerCLI -Scope CurrentUser
Note: Sometimes, when you install PowerCLI as a module, you can see the error:
The module 'VMware.VimAutomation.Sdk' cannot be installed or updated because the authenticode signature of the file 'VMware.VimAutomation.Sdk.cat' is not valid.
In this case, run the following command to install PowerCLI without errors:
install-module VMware.PowerCLI -scope AllUsers -force -SkipPublisherCheck -AllowClobber
- Check the PowerCLI version after finishing installation:
- You can set whether to participate in the VMware Customer Experience Improvement Program. To say No, run the command:
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
- List all available cmdlets after PowerCLI is installed:
Get-Command -Module *VMWare*
Get-Module -ListAvailable VMware* | Select Name,version
The command to update the PowerCLI module in PowerShell is:
Update-Module -Name VMware.PowerCLI
If you want to install a specific version, use the commands shown below.
- Check available vSphere PowerCLI versions in online repositories:
Find-Module -Name VMware.PowerCLI -AllVersions|select version
- Enter the needed version selected from the previous command output, for example, 18.104.22.16869701:
Install-Module -Name VMware.PowerCLI -RequiredVersion 22.214.171.12469701
Once the PowerCLI installation is completed, you can use VMware vSphere-related cmdlets in PowerShell.
- Check the connection to the server with the Connect-VIServer command and see whether there is a certificate error. Try to resolve the issue with the command:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
- If everything is correct, you can connect to a vCenter Server or ESXi host with the command:
Use the hostname or IP address of the needed server.
- Get a list of VMware VMs managed by the server to which you have connected:
Now you can run other commands and create scripts with VMware PowerCLI.
How to install PowerCLI with Chocolatey
Chocolatey is a package manager for Windows. It is used in PowerShell to install software packages from online repositories. Chocolatey (choco) uses NuGet to package software and is built on top of other Windows technologies. This package manager helps you manage software easily, including installing and uninstalling packages.
- Set the correct policy to install choco, if you have not installed it yet:
- Run this complex command to install choco:
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
- Search the VMware module in the online backup repository:
choco search vmware
- Install VMware PowerCLI with Chocolatey from the online software repository:
choco install vmware-powercli-psmodule
Type Y or A to continue.
- Wait for all package components to be downloaded and installed:
How to Install PowerCLI Offline
Not all servers can be connected to the internet due to security policies or other reasons. In this case, you can install VMware PowerCLI by using offline installation methods.
Installing PowerCLI offline by copying files
The first offline method to install PowerCLI involves using files downloaded from PS Gallery. The first steps are similar to the steps explained above when we need to find the module packages and install them in our Windows system.
- Find the PowerCLI module in PowerShell Gallery:
Find-Module -Name VMware.PowerCLI
- Download and save the PowerCLI module files for PowerShell to a specified directory, for example, C:\Temp\Modules\ with the command like:
Save-Module -Name VMware.PowerCLI -Path <path>
In our case, the exact command with the correct path is:
Save-Module -Name VMware.PowerCLI -Path C:\Temp\Modules
- Copy the downloaded files from the C:\Temp\Modules\ directory of your computer to a computer that is not connected to the internet.
Place the copied files to C:\Windows\System32\WindowsPowerShell\v1.0\Modules
Administrator rights are required.
- Unblock the downloaded files:
cd "C:\Program Files\WindowsPowerShell\v1.0\Modules"
Get-ChildItem * -Recurse | Unblock-File
- PowerCLI installation is completed. Now you should be able to use vSphere PowerCLI on a computer that is not connected to the internet.
How to install PowerCLI offline from a ZIP archive
VMware provides an offline installer, which you can download and use to install PowerCLI offline on multiple computers.
- Download the ZIP archive containing PowerCLI module files from the official VMware website:
The file name looks like VMware-PowerCLI-12.7.0-20091289.zip and the file size is about 100 MB.
- Copy the downloaded ZIP archive to a computer that is not connected to the internet.
- Extract the files to the directory where PowerShell modules are installed in Windows, for example, to
- PowerCLI installation is completed.
How to Install vSphere PowerCLI in Linux
VMware PowerCLI runs only in PowerShell, which is a native command line interface for Windows. However, many professionals use Linux and want to manage VMware vSphere environments directly from Linux. Installing a Windows virtual machine with PowerShell on it is not the case because we can install PowerShell and PowerCLI in Linux. We will install PowerCLI on Ubuntu Linux (v.20.04). Let’s look at how to do this.
Run the commands listed below as root (you can use the sudo -i command to get the root privileges).
- Update the package repository tree:
- Update the packages that have already been installed on your Ubuntu Linux system (recommended):
- Install curl (client URL), which is a tool to transfer data from and to a server in the command line with multiple protocols:
apt-get install curl
- Add the Microsoft repository containing PowerShell for Linux:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- Update the repository tree after adding the Microsoft repository. After running this command, the apt package manager will know about the newly added Microsoft repository:
Note: You may see the error:
W: GPG error: https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
E: The repository 'https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
To fix this issue, we need to add the mentioned EB3E94ADBE1229CF key manually. The apt package manager uses keys to install packages securely from trusted software repositories. If a key is missing to authenticate a package, the error occurs.
- Add the key with the command:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
- Update the repository tree once again:
- Install PowerShell in Ubuntu Linux:
apt-get install powershell
- To open a PowerShell session in the Linux console, run this command:
Note: We run PowerShell as root because it is required to install VMware PowerCLI in Linux. After installing PowerCLI, you can run PowerShell without elevated privileges.
- Install PowerCLI with the command:
Install-Module -Name VMware.PowerCLI
Press y or a to continue.
- Check the version of PowerCLI you have recently installed:
Get-Module VMware.PowerCLI -ListAvailable
To exit from PowerShell to the bash console, run the exit command. After finishing the PowerCLI installation, you can exit the root console and run commands as a regular user.
New PowerCLI versions are installed as PowerShell modules by using multiple online and offline methods in Windows and even in Linux. Whatever you use to manage your VMware vSphere environment, make sure to back up VMs and be prepared for any data loss eventuality. Consider NAKIVO Backup & Replication as a comprehensive data protection solution for virtual, physical, cloud, and SaaS environments, including VMware vSphere.
Download the Free Edition to start backing up your VMware vSphere VMs today.