VMware PowerCLI: Installation and Scripting Guide

Published:16 August 2019 - 6 min. read

The PowerCLI by VMWare is the de-facto way to manage vCenter with PowerShell. In this tutorial, you’re going to learn how to start from scratch; downloading, installing and understanding how PowerCLI can help you get more done.

Along this journey you will learn:

  • How to spot historical versions of PowerCLI that you may encounter in legacy scripts
  • How to install the most recent version of PowerCLI
  • Use VMware Code as a resource
  • How to install VMware PowerCLI across both Windows PowerShell 5.1 and PowerShell 6/7 for cross-platform use.

“In most respects, VMware PowerCLI is the most consistent administrative interface in the hypervisor’s tenured history.”

The above paraphrased comment was shared about the resilience and importance of PowerCLI in a system administrator’s toolkit. It was shared during a VMware PowerCLI session at the PowerShell Summit in 2019.

Interfacing with vSphere and VMware has gone through a multitude of iterations, from the original software client, flash client, HTML5 and flex web-client versions. In each new release, the interfaces changed in often buggy or feature-lacking ways.

Automate more than a local ESXi host and use PowerCLI with VMware vCenter to manage multiple hosts with ease. Host virtual desktops with VMware Horizon backed by VMware hosts.

On the flip side, VMware PowerCLI’s syntax has remained stable throughout its lifecycle with only one distribution change. That big change was the transition from a PowerShell snapin to PowerShell module.

PowerCLI is effectively the last man standing for consistency’s sake when administering VMware products.

From Snapin to no Public Access

The original download location for VMware PowerCLI was behind a PowerCLI 5.1 page link. Because of this restriction, the public only had limited access to this tool.

PowerCLI 5.1 and earlier was also a PSSnapin rather than a module making portability much more difficult. As a follower of this blog, you’ll likely recognize this as a legacy format for such tools. Because of the cumbersome installation steps, snapins proved more difficult to get mass-adoption of PowerCLI. Lucky for you, PowerCLI as of the latest version 6.0 ships as a PowerShell module, and not a snapin!

With that release of PowerCLI 6.0 in September of 2015, the game had begun to change. This version was the first iteration released as a PowerShell module, shipping with about 400 cmdlets total. However, the need for a my.vmware.com account was still present until version 6.5.1 released on 4/20/2017 to the PowerShell Gallery.

In the current version (11.3.0) of VMware PowerCLI, the module has just under 700 cmdlets for administrative coverage over a multitude of VMware products. Those products include vCenter, vCloud Director, VMware Horizon, and many others.

The list of cmdlets continues to grow with the VMware portfolio, but the tried and true PowerCLI standards are holding strong like a force of consistency.

Cmdlets in the PowerCLI PowerShell module
Cmdlets in the PowerCLI PowerShell module

Prerequisites

We’re about ready to jump into a demo so be sure you have all of these prerequisites so you can follow along with me.

  • VMware host or vCenter server for validation testing
  • Windows, Mac, or Linux client machine

Downloading VMware PowerCLI

The new long term home for the PowerCLI project team is set at this link. Any and all community raised feature requests, comments, and documentation for this module are now part of the same site as the SDK, API, and certification resources.

If you have any questions or wish to raise feature requests directly with the team, you can reach out to both the PowerCLI team and the community surrounding this project at code.vmware.com. Both the community and VMware project team are highly responsive to questions, concerns, and new ideas as they arise.

If you’d like to perform a PowerCLI download via the web, the PowerCLI team provides a direct link to two options for their PowerShell module:

  • The PowerShell Gallery link to download and install using PowerShell’s package manager
  • A .zip archive of the module’s contents, to be manually installed

The PowerShell Gallery is, by far, the most common way to download PowerCLI but the zip archive will also work. Note that you don’t have to use the PowerShell Gallery link here. You can also download it via PowerShell.

Installing VMware PowerCLI in Windows PowerShell

There are a few different ways to install PowerCLI.

Extracting the ZIP file

If you’ve downloaded it via the web from the aforementioned page, you’ll need to manually install it. You must get PowerCLI in a spot where PowerShell can see it.

To install the module via the provided zip package, you’ll need to extract the contents to the module location of choice. This location will either be your user profile location (for non-administrative scope) or to the system-wide modules folder.

%UserProfile%\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules

Extract the .zip contents to one of the above locations.

The easiest and fastest way you can download and install PowerCLI today is to use download the module from the PowerShell Gallery within a PowerShell console. Below you will find a quick video on the general installation steps for a new module to PowerShell with this method.

But, all-in-all, you can perform the following from an administrative PowerShell prompt to get the job done.

PS51> Install-Module VMware.PowerCLI

If you’d like to perform a PowerCLI install on a workstation where you lack administrative privileges, you can use the Scope parameter to install the module into your user profile module path.

PS51> Install-Module VMware.PowerCLI -Scope CurrentUser

Installing VMware PowerCLI in PowerShell 6 on Linux

Nowadays, you can also install PowerCLI on non-Windows systems. For example, we can install PowerCLI in PowerShell Core on Ubuntu. Again, depending on if you’ve chosen to download the zip file, the PowerShell Gallery’s web link or directly via the PowerShell console, the installation process is a little different.

Extracting the ZIP file

Depending on the flavor of Linux, you will extract the .zip file contents to different locations.

Open up PowerShell on Linux by running pwsh in your terminal. Locate the potential PSModulePath locations using the following command:

PS61> ($env:PSModulePath).split(":")
Directories in PSModulePath
Directories in PSModulePath

Once you’ve determined where you would like to install the module files, download them to that location and prepare for the unzip. You’ll either unzip them to the /home/ folder for user access or the /opt/ location for system access.

For this example of a Linux-based installation, I’m using Ubuntu 18.04 and will install VMware PowerCLI 11 using the .zip file downloaded from here, installing the module to be accessed by all users of this machine.

> cd /opt/microsoft/powershell/6/Modules
> sudo apt install unzip
> sudo wget https://vdc-download.vmware.com/vmwb-repository/dcr-public/8bf09c32-43c0-46d4-8816-92515c3b8228/15761272-b339-4da4-888a-4b8633f9a964/VMware-PowerCLI-11.3.0-13990089.zip
> sudo unzip ./VMware-PowerCLI-11.3.0-13990089.zip

You can then import this module, because the module files are now in one of your $PSModulePath locations, via a normal execution of:

Import-Module VMware.PowerCLI

Installing the Legacy VMware PowerCLI Snapin

Sometimes you may find yourself having to install the older PowerCLI snapin. Perhaps you have taken over responsibility for some legacy code and need to troubleshoot problems. To prevent re-architecting your existing scripts, it’s necessary to install the old snapin.

To install the old snapin, you’ll need a my.vmware.com account to login and retrieve the VMware-PowerCLI-5.1.0-3090428.exe file. Upon download, install the snapin via the executable through a normal Windows application installation.

You can then run Add-PSSnapin to load the VMware cmdlets into your session, or launch the provided VMware PowerCLI console in a stand-alone fashion.

Below you can see I’m using the Add-PSSnapin cmdlet to add PowerCLI version 5.1 to my current console session.

PS51> Add-PSSnapin VMware*
PowerCLI snapins
PowerCLI snapins

Launching the installed stand-alone VMware PowerCLI shortcut that gets installed with version 5.1.

PowerCLI v5.1 console
PowerCLI v5.1 console

Note that the above snapin is not compatible with PowerShell 6/7.

Verifying Installation of PowerCLI

Verifying your installation of PowerCLI as successful is the same, regardless of your version of PowerShell. The first step, confirm the presence of the modules from the PowerShell console.

Get-Module -ListAvailable VMware* 
Available PowerCLI modules
Available PowerCLI modules

Next, attempt to use PowerCLI to connect to vCenter with the Connect-VIServer cmdlet. This will not only verify the module was installed successfully, it will also test whether or not you connect to your infrastructure correctly.

On Windows

PS51> Connect-VIServer <FQDN of vCenter or ESXi Host>
Connecting to vCenter with VMware PowerCLI on Windows
Connecting to vCenter with VMware PowerCLI on Windows

On Linux

When verifying installation on Linux, you must first set the connection configuration to account for an invalid (or default self-signed certificate) if you encounter any connection issues. Below I am using PowerCLI to connect to vCenter.

PS> Set-PowerCLIConfiguration -InvalidCertificateAction:ignore
PS> Connect-VIServer <FQDN of vCenter or ESXi Host>
Connecting to vCenter with VMware PowerCLI on Linux
Connecting to vCenter with VMware PowerCLI on Linux

Since you were able to successfully connect to your VMware endpoint, the PowerCLI is successfully up and running!

Go Forth and PowerCLI!

Automate more than a local ESXi host and use PowerCLI with VMware vCenter to manage multiple hosts with ease. Host virtual desktops with VMware Horizon backed by VMware hosts.

From this point on, you are now prepared to answer that proverbial question of “How do I install VMware PowerCLI?”. You can now begin working on scripting out your configuration deployments, VM Reports, and maintenance tasks. Stay tuned to this blog for new and upcoming articles on getting started with PowerCLI!

Further Reading

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!