Release date: September 10th 2021
Welcome to my VMware PowerCLI section. In this section I will detail how I set up PowerCLI mainly to be used with VMware Horizon, both online and offline. The easiest way to do this is to download PowerCLI on an internet connected Windows VM. Using the command below will download the PowerCLI modules to the a local folder, “C:\tmp\PSModules”, the folder has to exist upfront.
Save-Module -Name VMware.PowerCLI -Path C:\tmp\PSModules
Although, running the command above, unfortunately returned the errors below
The reason for these errors, as I understand it, is that PowerShell by default uses TLS 1.0 for web requests, which causes these errors. To work around this, I ran the following command before i retried the initial download command above.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
I could now download the modules to “C:\tmp\PSModules”
Next, I copy the content of “C:\tmp\PSmodules” to “C:\Program Files\WindowsPowerShell\Modules”, which requires administrative privileges in Windows. Once done, I import the modules into Powershell
Set-ExecutionPolicy RemoteSigned Get-Module -ListAvailable VMware* | Import-Module
I can now list and verify the version of the PowerCLI modules by running the following command
Get-Module -ListAvailable VMware*
As I mentioned to begin with, I will mainly be using PowerCLI with VMware Horizon. To do this, I will need the module Vmware.Hv.Helper. Therefore I download this as described here: Automating VMware Horizon 7 with VMware PowerCLI As with the other modules above, I copy this to the “C:\Program Files\WindowsPowerShell\Modules” folder. I run the command below to unblock the advanced features of the Vmware.Hv.Helper module
dir 'C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\' | Unblock-File
Having done all this, I thought I was ready to start creating and running scripts to automate my VMware Horizon operations. NOT! As I discovered, there is a bug in the Vmware.Hv.Helper module, that will result in errors like the one shown below.
The reason for this is the PowerCLI 12.x.x versions. To work around this, I will first need to download PowerCLI v.12.0.0. Next, I will uninstall the 12.x.x versions I downloaded above, using the following command:
Get-Module VMware.* -ListAvailable | Uninstall-Module -Force
Then I delete all VMware.* folders under “C:\Program Files\WindowsPowerShell\Modules” except the VMware.Hv.Helper folder. I extract the downloaded PowerCLI 12 zip file and copy all files and folders to PowerShell’s module directory and run the following command to unblock the modules
Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\' -Recurse | Unblock-File
Finally, I verify the PowerCLI modules versions using the command below
Get-Module -ListAvailable VMware*
And that concludes the “online” setup of PowerCLI, to facilitate Automation of different VMware Horizon operations. As I quite often run into environments which have management servers without internet connectivity, I often have to make offline setups. T do this, I extract the PowerCLI 12.0.0 zip file I downloaded above to a temporary folder and add the VMware.Hv.Helper folder to this.
I then transfer this folder to the offline system and copy them to “C:\Program Files\WindowsPowerShell\Modules”. I import the modules and unblock, same as above.
Set-ExecutionPolicy RemoteSigned Get-Module -ListAvailable VMware* | Import-Module Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\' -Recurse | Unblock-File
At the same time I make the following adjustmenst to CEIP and Ignore SSL Cert warnings
Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCeip $false -confirm:$false Set-PowerCLIConfiguration -Scope AllUsers -InvalidCertificateAction Ignore -confirm:$false
Finally, I’m good to go. I can now start scripting automation for VMware Horizon operations, which I have covered here:
Big thanks to the guys mentioned below for helping me in the right direction:
MICHAEL SCHROEDER’s post: PowerCLI offline installation
Graeme Gordon’s post: Automating VMware Horizon 7 with VMware PowerCLI
Eric Monjoin’s post: PowerCLI and VMware Horizon.. error BaseImageVM_List
Disclaimer: Every tips/tricks/posting I have published here, is tried and tested in different it-solutions. It is not guaranteed to work everywhere, but is meant as a tip for other users out there. Remember, Google is your friend and don’t be afraid to steal with pride! Feel free to comment below as needed.