ControlUp 8.1 integrates with Horizon, VMware’s virtual desktop infrastructure (VDI) solution. By itself, the ControlUp Management Console (CMC) is a powerful monitoring tool for Horizon, but to fully utilize the power of CMC, you should use it with ControlUp Script Actions (SAs). By doing so, you can begin the journey to a self-managing and a self-healing VDI environment, reducing the time you spend troubleshooting and fixing issues so you can spend more time on strategic projects.
Microsoft PowerShell is the scripting language of choice for SAs, and VMware created PowerCLI to allow VMware solutions to interact with PowerShell. PowerCLI provides more than 700 cmdlets for managing and automating VMware’s various solutions, including vSphere, vROPs , vSAN, NSX-T, and Horizon.
Although relatively simple to install and use, PowerCLI does have a few gotchas, so in this article I will provide you with a step-by-step guide on how to set up and use PowerCLI. For convenience, I will be installing it on a Windows 10 virtual machine running in my home lab, but these same steps will work in larger environments and with Windows Server.
To show you how to install the components needed to create an environment in which SAs can execute, I started out with a fresh install of Windows 10 on a dual-proc 4GB virtual machine (VM) with 64 GB storage being hosted on an ESXi 6.7 server.
PowerShell is installed by default on Windows 10. I started PowerShell by entering PowerShell in Windows Search, and then selected Run ISE as Administrator.
The PowerShell Integrated Scripting Environment (ISE) is used to create, run, and debug commands and scripts. The ISE consists of a menu bar, Windows PowerShell tabs, toolbar, script tabs, Script Pane, Console Pane, status bar, text-size slider, and context-sensitive Help.
To verify which version of PowerShell I was using, I entered Get-Host | Select-object Version, and then entered $PSVersionTable in the Console Pane; both of these commands showed that I was running PowerShell 5.1.
There are different ways that you can download and install PowerCLI (e.g., from the VMware website, etc.), but most users find it easiest to install it directly from PowerShell using the following commands:
I listed all of the PowerCLI modules by entering Get-Command -Module *VMWare* (Figure 3).
To test if PowerShell was installed and working properly, I created the following script to connect to my vCenter Server and list all the virtual machines (VMs) powered on within the vCenter Server:
If you want to create a script that you can reuse, select New from the File drop-down menu of the ISE, then save the file to the location of your choice. To run it, select the Run icon (green right arrow) on the ISE menu bar.
One of the reasons I like using the PowerShell ISE is that I can use the context-sensitive pane to help me craft my PowerCLI commands.
There are different ways you can install the Horizon API Module but, again, most users find it easiest to install it from PowerShell directly by entering Get-Module –ListAvailable VMware*Horizon* | Import-Module in the ISE console.
Using PowerCLI Horizon
Once you have the Horizon module imported, you can use Connect-HVServer cmdlet to establish a connection to the Horizon API service of the Horizon Connection server:
To list all the Horizon sessions that are active, enter the following:
By using VMware’s PowerCLI, along with its Horizon add-on library, you can create PowerShell scripts to do just about any monitoring function that you could normally carry out with the vSphere Client or the Horizon Console.