PowerCLI and VMware Horizon View

3 min read
Power CLI and VMware Horizon

Introduction

VMware PowerCLI has been in existence for quite some time.  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 concert with automation and orchestration tooling, a great many bespoke capabilities are also available.

Being based on PowerShell, it can be used in concert with third party modules such as those administering Active Directory to provide an integrated solution across a wide range of products.

For this blog, I take a look at PowerCLI’s ability to support VMware Horizon.

Powercli Supports Horizon Pic1

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 () allowing installation on a connected PC straight from the PowerShell interface, simply by running:

Install-Module -Name VMware.PowerCLI

P1-Ps-C-Windows-System32-Install-Module-Name-Vmware-Powercli

You might then get something like this (just accept the default):

Nuget Provider Is Required To Continue

Then it will install…

Installing Package 'Vmware.powercli'

Then, to allow execution of local scripts:

Set-ExecutionPolicy RemoteSigned
P4-Ps-C-Windows-System32-Set-Execution-Policy-Remotesigned

Run the following to confirm it’s all installed successfully.

P5-Ps-C-Windows-System32-Get-Module-Vmware-Listavailable

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

P6-Ps-C-Windows-System32-Setpowercliconfiguration-Scope-User-Participateinceip

After that, the basic PowerCLI is ready to go.

What can we do for Horizon?

‘Out of the box’, Power CLI 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

P7-Ps-C-Users-Administrator-Connect-Hvserver-Galwhz01-Galaxy-Lcl

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 is the user specific path, plus system ones)

P8-Ps-C-Windows-System32-Senv-Psmodulepath

For Horizon, we extract the ‘VMware.hv.helper’ module from the ZIP and drop this into C:\Program Files\WindowsPowerShell\Modules.

Vmware.hv.helper

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-HVHealth will display the current health summary:

P10-Ps-C-Users-Administrator-Get-Hvhealth

And we can see how many VMs are available:

P11-Ps-C-Users-Administrator-Get-Hvmachinesummary-State-Available

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’:

Vmware Horizon Test Pool

Closing Thoughts

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.  Furthermore, 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 really is the limit!

If you’re planning to deploy a Virtual Desktop solution, Xtravirt are able to provide design, implementation and support services – not just for standard ‘off the shelf’ solutions, but for more customer-specific requirements. To understand and experience digital workspace solutions for your organisation, why not take a look at our Customer Experience Centre (CEC). The CEC includes a fully featured modern digital workspace based on VMware Horizon and Workspace ONE in an immersive demo environment which can enable you to bring your plans to life.

Xtravirt Customer Experience Centre - Test Drive Your Future-State - Discover The Cec

To understand more about how you can accelerate your digital transformation journey,  contact us and we’ll be happy to use our wealth of knowledge and experience to assist you.

share
Table of Contents
Subscribe to the Xtravirt Newsletter

Receive updates from the Xtravirt team, including information on new technologies and the expert analysis of cloud trends and strategies you should know about, unsubscribe anytime using the link included in every email.

Solutions Architect