VMware PowerCLI has been in existence for quite some time and over the last 2 years it has been moving at quite a rapid pace. It has traditionally been used to provide PowerShell based command and control functionality within VMware vSphere environments, with particular focus on the ability to create scripted functions for automation purposes. Used in conjunction with automation and orchestration tooling, a great many bespoke capabilities are available.
During 2018, there has been a release around every 2 months, the current release, version 11 was released in October and provides support for the following:
- vSphere 6.7U1
- VMware Horizon 7.6
- NSX-T 2.3
- VMware Cloud on AWS
Being based on PowerShell, it is also compatible with third party modules, such as those administering Active Directory, to provide an integrated solution across a wide range of products.
In this blog, I look at PowerCLI’s ability to support VMware Horizon.
Installing VMware PowerCLI
Installing PowerCLI was once a case of downloading an installer from the VMware Portal and installing the components. However, PowerCLI is now published from the PowerShell Gallery on the internet (https://www.powershellgallery.com/packages/VMware.PowerCLI/184.108.40.20680590) permitting installation on a connected PC straight from the PowerShell interface, simply by running:
Install-Module -Name VMware.PowerCLI
You might get something like this (accept the default):
Then it’ll install…
To allow execution of local scripts:
Then, run the following to confirm it’s all installed successfully.
Once installed, it’s worth configuring the Customer Experience Program participation by Enabling or Disabling this (It stops nag messages).
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true $false
After that, the basic PowerCLI is ready to go.
What can we do for Horizon?
‘Out of the box’, PowerCLI only provides the ability to connect or disconnect to the Connection Server, so providing a conduit for accessing the Horizon APIs. To connect to Horizon Connection Server:
Connect-HVServer -Server connectionserverFQDN -user adminuser@domain -Password XXXX
However, VMware maintain example scripts at https://github.com/vmware/PowerCLI-Example-Scripts that can be used as a basis for automation of Horizon and the other supported components.
By downloading the scripts as a ZIP file, it is possible to install them. First, check $env:PSModulePath to locate the modules directory paths (usually, there’s the user specific path, plus system ones)
For Horizon, we extract VMware.hv.helper from the ZIP and drop this into C:\Program Files\WindowsPowerShell\Modules.
In PowerShell, we then unblock the newly exported folder by running
dir ‘C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\’ | Unblock-File
With this in place, we can now use a whole raft of useful PowerShell commands (they can be listed by using Get-Command -Module ‘VMware.Hv.Helper’). These can be used for automation of tasks and generating reports.
For example, Get-HVPoolSummary will list configured pools, including their type, assignment type and status:
And we can see how many VMs are available:
Get-HVHealth shows a basic status:
By leveraging the ‘New‘ and ‘Remove’ commands, it is possible to provision and destroy new Pools (desktops and applications), entitlements, RDS Farms and Cloud Pod objects such as Sites and Entitlements. For Example, setting up Shared Desktop pool ‘Teachers 1’:
What we have here is a set of powerful tools that are not just capable of managing the VMware vSphere infrastructure, but can also expand into the realm of delivering desktop pools – all from scripting and automation. For example, it would be possible to create a script that would leverage PowerShell to create an Active Directory Group and populate it, then create a desktop pool and grant the members of the group access to it. Further, this could be used in concert with vRealize Automation and Orchestration to provide a portal for self service requests for generating desktop pools and services.
Given that the current release supports VMware Cloud on AWS as well as VMware Horizon, this offers the tantalizing prospect of being able to programmatically manage a federated on-prem and AWS hosted Horizon Cloud Pod Architecture. The sky is the limit!
If you’re planning to deploy a Virtual Desktop solution, we can help. Xtravirt provide design and implementation services to create the right solution for your organisation. Contact us and we’d be happy to use our wealth of knowledge and experience to assist you.