ControlUp Script Actions for VMware Horizon

Editor’s Note: Guy Leech, a Citrix CTP and former VMware vExpert, has 25 years’ of Citrix experience, especially troubleshooting Citrix environments, plus years as a developer writing functional and efficient Powershell scripts. He has published over 50 ControlUp Community Scripts that can be leveraged manually, used based on guidance from our Virtual Expert, or automated via Automated Actions.

Introduction

This post will focus on two new scripts that leverage ControlUp’s new native Horizon integration. Show Horizon View Usage pulls data from the Horizon API to display usage figures in a given time period. The Analyze Logon Duration for VMware Horizon script provides information on a specific user’s logon stages, logon stage duration, and delays in the logon process.

Show Horizon View Usage

Horizon can be configured with a Microsoft SQL Server database as a store for events generated by Connection Servers and the end-points running the Horizon agent. This database will contain warnings and errors when there are issues in the environment but also, once a day, will write usage figures to the log, including the following:

  • Total number of users for the 24 hour period
  • Maximum number of concurrent users for the 24 hour period

While this data is available in the SQL database, current Horizon consoles are not able to easily present the data other than in a table format, which makes the data difficult to visualize. This new PowerShell script uses VMware PowerCLI to retrieve this data and present a visual summary to the user running the script.

I used Windows Forms to graph the data points so the admin can see trends, peaks and troughs, etc. Like other scripts that display a GUI, this script must be run when the console is running.

This script has a prerequisite of the VMware PowerCLI PowerShell modules being available on the machine running the ControlUp console. If they are not already installed, they can be installed by running “Install-Module VMware.PowerCLI” from an elevated PowerShell prompt on the server where the ControlUp console will be used.

Once the specified VMware Horizon server has been connected to using Connect-HVServer, a query is constructed to retrieve the Horizon View events within the preceding number of days specified as an argument which match one of the following event types:

Event Type Meaning
BROKER_DAILY_MAX_APP_USERS Maximum Application Users
BROKER_DAILY_MAX_CCU_USERS Maximum Concurrent Users
BROKER_DAILY_MAX_DESKTOP_SESSIONS Max Desktop Sessionsimum

These events are created automatically once every 24 hours by a Horizon server and help administrators, support, etc to view system usage. The script retrieves these values and creates a Windows Form Charting object to which the retrieved events are added, after which the form is displayed via its ShowDiaog() method.

Windows Form Charting object

Thanks to Andy Morgan of VMware (@andyjmorgan) for the code on GitHub that helped me to write this script.

Analyze Logon Duration for VMware Horizon (ALDVH)

This script retrieves specific events from various Windows event logs to produce a view of a specific user’s logon stages and the durations of those phases, plus any delays between stages. It also shows the durations of user-assigned Active Directory logon scripts and all scheduled events set to run at logon for that user. When the script is passed credentials that allow it to retrieve data via an OData API, it will also display that user’s Citrix Brokering duration before logon is initiated on a Windows machine.

This VMware Horizon data is written by the Horizon Agent to the registry on the Windows machine on which the user is logged and on which the ALDVH script must run (elevated). Note that the “ProfilerData” value is written asynchronously and may not appear until several minutes after the user’s logon has completed.

If ALDVH detects that the VMware Horizon Agent (WSNM) service is installed, it checks for the presence of the registry key:

“HKLMSOFTWAREVMware,Inc.VMwareVDMSessionData$SessionId”

…where “$SessionId” is replaced by the session id of the user for which the script is being run.

Analyze Logon Duration (ALD)

The ViewClient_* values give useful information such as the protocol being used (ViewClient_Protocol) and brokering details. The ProfilerData value contains the most interesting information – timing details of the connection/logon process.

The profiler data is in JSON format, which is easy to convert to PowerShell objects by way of the ConvertFrom-Json cmdlet.

Convert From Json

Here are the single letter keys as defined here:

Field Meaning
s Start time
e End Time
d Duration (milliseconds)
u Unaccounted time
unadjusted-s Start timestamp from desktop VM
unadjusted-e End timestamp from desktop VM
unadjusted-d Duration calculated by unadjusted-e and unadjusted-s

You can also drill down to child activities of these instances:

drill down to child activities

As with all ControlUp scripts, they can be downloaded (from here) and run outside of the ControlUp products but you may need to supply arguments as required by the scripts. For instance, here is an example of the script run by an administrator after a user session. The highlighted section contains the Horizon-specific information retrieved from the registry for the user “billybob” in session 6.

Horizon-specific information retrieved from the registry

Keep an eye out for more Horizon scripts, and feel free to suggest ideas for scripts that would benefit the ControlUp Community.