PowerShell

Install VMware PowerCLI

Install VMware PowerCLI

VMware regularly releases updates to its Powershell module, known as PowerCLI. While in the past you had to go to the vmware.com website, download the executable - by the way, you still can for older versions - and install PowerCLI, you no longer have to since there’s an easier way directly from a PowerShell console.

If you do have an older version that was installed via an executable installer, please uninstall it via Apps & features under System Settings before proceeding with the examples shown here.

Checking PowerShell Version

There is a requirement for installing PowerCLI, and that is to have, at a minimum, PowerShell 3.0 installed. If you have the latest Windows 10 release, you will have no problem installing it. If you need to verify the version installed on your system, run the following command and look for the PSVersion in the output:

PowerShell
$PSVersionTable

The text will be the output you should see:

PowerShell
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.18362.145
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.145
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

The installed version on my machine is PSVersion 5.1.18362.145 or simply 5.1, as highlighted on line 4.

How To Install PowerCLI

Run the following command to install the latest version of PowerCLI.

PowerShell
Install-Module VMware.PowerCLI

If you need to install a specific version of PowerCLI, you may run the following:

PowerShell
Install-Module -Name VMware.PowerCLI -RequiredVersion 10.1.1.8827524

To list all the versions available for install, type the following:

PowerShell
Find-Module -Name VMware.PowerCLI  -AllVersions | Format-Table -AutoSize

Uninstall PowerCLI

To uninstall PowerCLI, type the following command to include all available versions of the module:

PowerShell
Get-Module -Name VMware* -ListAvailable | Uninstall-Module -Force

Connect to VMware vCenter Server using PowerCLI

First, let’s save our credentials to a temporary variable by typing the following:

PowerShell
$cred = Get-Credential

You should see an authentication dialog box. Enter your credentials.

authentication dialog box

By creating a temporary variable that stores your credentials, you can log in to multiple vCenter Servers or reuse it to login again if you lose your connection to vCenter Server.

Next, type the command below and subsite the name of your vCenter Server. The example here includes the name of my vCenter Server, vcenter.virtual.local.

PowerShell
Connect-VIServer -Server vcenter.virtual.local -Credential $cred

If you connect successfully, you will see the following output showing the name of your vCenter Server.

PowerShell
PS C:\> Connect-VIServer -Server vcenter.virtual.local -Credential $cred
Name Port User
---- ---- ----
vcenter.virtual.local 443 VSPHERE.LOCAL\Administrator

Running Basic CMDLETs

Now that you’ve connected successfully, let’s run the following cmdlets:

PowerShell
Get-Datacenter
PowerShell
Get-Cluster
PowerShell
Get-VMHost
PowerShell
Get-VM
PowerShell
Get-Datastore

As you can see, those basic cmdlets retrieve a lot of useful information on your environment.

Enjoy learning PowerShell.