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.

Contents:

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.

Install PowerCLI PowerShell

  1. To install PowerCLI module for all users, run the command:

Install-Module -Name VMware.PowerCLI

The latest version of PowerCLI is installed by default.

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

How to install PowerCLI via PowerShell (PS Gallery) - error message

In this case, run the following command to install PowerCLI without errors:

install-module VMware.PowerCLI -scope AllUsers -force -SkipPublisherCheck -AllowClobber

How to install PowerCLI module in PowerShell without errors

  1. Check the PowerCLI version after finishing installation:

Get-PowerCLIVersion

Checking the version after installing PowerCLI

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

  1. List all available cmdlets after PowerCLI is installed:

Get-Command -Module *VMWare*

or

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.

  1. Check available vSphere PowerCLI versions in online repositories:

Find-Module -Name VMware.PowerCLI -AllVersions|select version

How to install vSphere PowerCLI of the needed version

  1. Enter the needed version selected from the previous command output, for example, 12.4.1.18769701:

Install-Module -Name VMware.PowerCLI -RequiredVersion 12.4.1.18769701

Once the PowerCLI installation is completed, you can use VMware vSphere-related cmdlets in PowerShell.

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

  1. If everything is correct, you can connect to a vCenter Server or ESXi host with the command:

Connect-VIServer 10.10.10.11

Use the hostname or IP address of the needed server.

  1. Get a list of VMware VMs managed by the server to which you have connected:

Get-VM

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.

  1. Set the correct policy to install choco, if you have not installed it yet:

Set-ExecutionPolicy AllSigned

  1. Run this complex command to install choco:
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object
System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))
  1. Search the VMware module in the online backup repository:

choco search vmware

Searching for VMware packages in software repositories online to install PowerCLI

  1. Install VMware PowerCLI with Chocolatey from the online software repository:

choco install vmware-powercli-psmodule

Type Y or A to continue.

How to install vSphere PowerCLI with Chocolatey in PowerShell

  1. Wait for all package components to be downloaded and installed:

Installing PowerCLI with choco

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.

  1. Find the PowerCLI module in PowerShell Gallery:

Find-Module -Name VMware.PowerCLI

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

How to install PowerCLI offline – using files from another computer

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

How to install PowerCLI offline – copying PowerShell modules as files manually

  1. Unblock the downloaded files:

cd “C:\Program Files\WindowsPowerShell\v1.0\Modules”

Get-ChildItem * -Recurse | Unblock-File

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

  1. Download the ZIP archive containing PowerCLI module files from the official VMware website:

https://developer.vmware.com/web/tool/vmware-powercli

The file name looks like VMware-PowerCLI-12.7.0-20091289.zip and the file size is about 100 MB.

  1. Copy the downloaded ZIP archive to a computer that is not connected to the internet.
  2. Extract the files to the directory where PowerShell modules are installed in Windows, for example, to

C:\Windows\System32\WindowsPowerShell\v1.0\Modules

  1. 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).

  1. Update the package repository tree:

apt-get update

  1. Update the packages that have already been installed on your Ubuntu Linux system (recommended):

apt-get upgrade

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

  1. Add the Microsoft repository containing PowerShell for Linux:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

curl -o /etc/apt/sources.list.d/microsoft.list
https://packages.microsoft.com/config/ubuntu/20.04/prod.list
  1. 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:

apt-get update

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.

Installing PowerShell in Linux for PowerCLI installation

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.

  1. Add the key with the command:

apt-key adv –keyserver keyserver.ubuntu.com –recv-keys EB3E94ADBE1229CF

Adding the key to install PowerShell in Linux

  1. Update the repository tree once again:

apt-get update

  1. Install PowerShell in Ubuntu Linux:

apt-get install powershell

  1. To open a PowerShell session in the Linux console, run this command:

pwsh

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.

  1. Install PowerCLI with the command:

Install-Module -Name VMware.PowerCLI

Press y or a to continue.

How to install PowerCLI in Ubuntu Linux

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

Conclusion

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.

People also read