Close

PowerCLI and VMware Horizon View

Curtis Brown

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

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
PS C:Windows\system32>set-ExecutionPolicy RemoteSigned

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

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

PS C:\Windows\system32>SetPowerCLIConfiguration -Scope User -ParticipateInCEIP $false

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

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)

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:

PS C:\Users\Administrator>get-hvhealth

And we can see how many VMs are available:

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.

Want to start your
Digital Transformation journey?

subscribe

Get the latest developments and insights from our award winning team