PowerCLI help installation, updating and troubleshooting tips

PowerCLI is a must-have tool for every VMware Administrator when you want to automate something in your VMware environment. In this blog, I highlight the installation, updating, and some troubleshooting tips for deploying and running PowerCLI on Windows OSes.

PowerCLI installation

  • Uninstall PowerCLI 6.x and earlier from the Add/remove programs or Programs and Features if exist.
  • Make sure you have an internet connection.
  • Check if Windows Management Framework 5.1 is installed for Windows 7,8 and Windows Server 2012 R2 and earlier OSes. Open PowerShell en enter:
$PSVersionTable
PS C:\$PSVersionTable

Name Value
---- -----
PSVersion 5.1.17763.592
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.592
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
  • If WMF 5.1 is not installed. Install the WMF 5.1 can be downloaded here, link. Windows 10, Windows Server 2016, and above have PowerShell version 5.1 already installed.
  • Installation PowerCLI
PowerCLI installation with admin rights:
Install-Module VMware.PowerCLI -AllowClobber -SkipPublisherCheck

Use the -AllowClobber when you get: A command with the name 'Export-VM' is already available on this system.
Install-Module VMware.PowerCLI -AllowClobber

Installation of PowerCLI without admin rights:
Install-Module VMware.PowerCLI -Scope CurrentUser

These modules are installed in the %homepath%\Documents\WindowsPowerShell\Modules
  • Allow the execution of local scripts
Admin rights needed:
Set-ExecutionPolicy RemoteSigned
  • Disable certificate checking and CEIP
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false -ParticipateInCeip $false
  • PowerCLI upgrade fails with a certificate error. The following error can occur when try to upgrade VMware.PowerCLI.

Install-Module VMware.PowerCLI -Force -SkipPublisherCheck

Install the VMware Horizon Module

  • Download the Horizon modules from GitHub: Link
  • Extract it
  • Copy the VMware.Hv.Helper folder to the modules path

Updating PowerCLI

The following steps can be used to update a PowerCLI 10 or 11 installation

  • Make sure you have a internet connection.
  • Check the PowerCLI version
Get-Module VMware* -ListAvailable
  • Update the existing PowerCLI version
Update-Module -Name VMware.PowerCLI
  • Check the version of PowerCLI
 
Get-Module -Name VMware.PowerCLI -ListAvailable

Troubleshooting PowerCLI

The following troubleshooting options can be used when having problems with the installation and running of PowerCLI such as:

Could not load file or assembly……………….

  • Disable the Anti Virus.
  • Uninstall PowerCLI 6.x and earlier from the Add/remove programs or Programs and Features if exist.
  • Uninstall PowerCLI.
Get-Module VMware.PowerCLI -ListAvailable | Uninstall-Module -Force
  • Check the  paths for VMware modules entries in the path. Remove VMware folder if exist.
$env:PSModulePath.Split(';')
  • List All the VMware modules and remove VMware modules.
Get-Module -Name VMware* -ListAvailable
  • Check for old PowerCLI modules and installations such as:
C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules
  • List registered snapins.
Get-PSSnapin -registered
  • Delete the registry keys of the old PS snapins.

  • Reboot the Windows system.

Try to install the PowerCLI module using a clean install as described above.

 

VIBSearch Finding VIB versions

VIBSearch is a simple PowerShell script with a GUI that will search for a specified VIB or all the VIBS installed on the ESXi hosts. A VIB stands for vSphere Installation Bundle (VIB). VIBs are used to package and distribute ESXi software such as drivers. The GUI is designed with SAPIEN PowerShell Studio 2014.

With VIBSearch it is easily to verify that all the ESXi host in the cluster have the same VIB versions installed. VIBSearch can be used for example to easily identify the HP-AMS driver version on all the ESXi hosts.

Requirements

VIBSearch is tested with:

  • PowerShell 5
  • The latests PowerCLI modules
  • For the Out-GridView cmdlet, PowerShell ISE is needed. Install ISE by using the following PowerShell commands:
    • Import-Module ServerManager
    • Add-WindowsFeature PowerShell-ISE

Installing and executing VIBSearch

  • Download VIBSearch.txt, link
  • Open PowerShell and execute:
    • Set-ExecutionPolicy  unrestricted
    • ./vibsearch.ps1

After executing the script the following GUI appears:

0

  • To connect enter the FQDN or IP address of the vCenter name (1) and click on Connect (2) button

1

  • A credential window appear, enter the credentials for authenticating (administrator) to the vCenter Server. For a domain login use: user user@domainname  or domainname\username

5

  • After successfully authenticating to the vCenter Server there are two options to choose:
    • List All the VIBS:  List all the ESXi hosts in the vCenter Server
    • Search VIB: specify a VIB name for example “HP-AMS”

6

If authentication to the vCenter Server fails the following error is displayed in the PowerShell window:

authen

Example output:

HP-AMS VIB versions

hpams

Intel NIC VIB “net-igb” versions

Intel

NVIDIA VIB versions:

nvidia

Thanks to Francois-Xavier Cat (@LazyWinAdm) for helping me with the VIBSearch tool.

 

Hyper-V Get Snapshot checkpoint file sizes on Cluster Shared Volumes with PowerShell

During a Windows Server 2012 Hyper-V Health Check I needed to know the snapshot file sizes for the all the snapshots on the Clustered Shared Volumes (CSVs). The Get-VMCheckpoint Cmdlet does not report the snapshot size. So I create a PowerShell one-liner that displays the following information:

  • Location of the snapshot file
  • Date and time that the snapshot file was created
  • Last write access time of the snapshot file
  • File size in MBs

The PowerShell one-liner is executed from a Hyper-V 2012 host that has access to all the  Cluster Shared Volumes (CSVs).

Get-ChildItem C:\ClusterStorage\ * -include *.avhd -recurse  | Select-Object Fullname,CreationTime,LastWriteTime,@{"Name"="Size (MB)"; "Expression"={[int]($_.Length/1mb)}} | Out-GridView

This PowerShell one-liner produces the following output:
image