Skip to main content

Automation with Horizon View Post 7.0.2 Version

If anyone has been working with Horizon View for a long time you will remember that prior to Horizon View version 7.0.2 you had to run powershell commands for Horizon View on the local connection server or use powershell remoting. Now with Horizon 7.0.2 and newer you can run powershell commands using PowerCLI from a remote system. In this blog I will go over the requirements needed, how to get started, examples, and some resources that you can use to expand what is covered here.

What is PowerCLI:
PowerCLI is a powerful command-line tool based on Windows PowerShell that lets you automate all aspects of vSphere vSAN, SRM, VROPS, vCloud, and Horizon View. within PowerCLI is 100's of cmdlets to be used to create the automation.

VMware PowerCLI - Horizon Module allows for integrated powershell support for Horizon View and is shipped as a module with the PowerCLI product. This allows access to the full Horizon View public API and supports remote connections from workstations or servers.

Requirements and Install for using PowerCLI with Horizon View:
Horizon View Environment must be running version 7.0.2 or newer
Local System Requirements:
  • Windows 7 SP1, 8.1, or 10
  • Windows Server 2008 R2, 2012 R2
  • PowerShell 3, 4, 5.x 
  • .Net Framework 4.5, 4.6
Optional Advanced Functions Download - https://github.com/vmware/PowerCLI-Example-Scripts
Prerequisites for setup:
  1. PowerShell version 5 or you will need to manually install PowerShellGet
  2. Uninstall PowerCLI 6.5 R1 or older from system
  3. Working Internet Connection
Installation:
  1. Open Powershell Session
  2. Run the following command: Install-Module VMware.PowerCLI -Scope CurrentUser
Note: PowerCLI modules will be saved to the following directory $home\Documents\WindowsPowerShell\Modules

### Import the Horizon View PowerCLI Module
### This will import the Horizon View module to windows powershell and make the cmdlets available
1:  Get-Module -Name VMware.*View -ListAvailable | Import-Module  
### Import the Horizon View Advanced Functions PowerCLI Module
### This will import the Horizon View Advanced Functions module to windows powershell and make the cmdlets available
1:  Get-Module -Name VMware.Hv.Helper -ListAvailable | Import-Module  
### To see the available cmdlets for Horizon View module run the following command
1:  Get-Command -Module VMware.VimAutomation.HorizonView | Format-Table -AutoSize  
Examples:
Below I will go over some basic examples of how to use PowerCLI with Horizon View
### How to connect to a Horizon Connection Server
1:  $hvServerPrd = Connect-HVServer -Server vcs01.corp.local  
### How to access the View API
### After running this command you can use $viewAPI to access the View API Methods
1:  $viewAPI = $hvServerPrd.ExtensionData  
When working with the View API you will have to know the API calls needed or look up the API calls needed for what you are looking for based on Horizon View API 7.1. As seen below are a few simple examples of doing this.

### Example of using View API to get a list of Connection Servers
1:  $viewAPI.ConnectionServer.ConnectionServer_List()  
### Example of using View API to get a list of vCenter Servers
1:  $viewAPI.VirtualCenter.VirtualCenter_List()  
For a little easier way to create automation i would recommend using the Advanced Functions in VMware.HV.Helper module. Below are a few basic examples of using this module, and you can see that there is not much to them and you don't have to know the API calls.

### This command will list all desktops in the Horizon Environment
1:  Get-HVMachine  
### Another option to list desktops in the Horizon Environment and a little easier to read.
1:  Get-HVMachineSummary  
### How to disconnect from a Horizon Connection Server when you are finished
1:  Disconnect-HVServer -Server vcs01.corp.local  
Resources:

PowerCLI Download
VMware Advanced Functions Download
PowerCLI Communities
PowerCLI 6.5.1 User Guide
PowerCLI cmdlets Reference Guide
Horizon View API 7.1

Comments