You can setup the Horizon PowerCLI module with VMware PowerCLI and use the Horizon PowerCLI cmdlets to connect or disconnect from Connection Server. After you connect to the Connection Server, you can write PowerShell scripts that invoke the Horizon APIs.
Procedure
- Install VMware PowerCLI.
Install VMware PowerCLI from the PowerShell Gallery. To install VMware PowerCLI, run the following command in the Windows PowerShell prompt:
Install-Module -Name Vmware.PowerCLI
This command installs all the VMware PowerCLI modules into Windows PowerShell. The VMware.VimAutomation.HorizonView
module is the Horizon PowerCLI module.
You can also download and install VMware PowerCLI from https://code.vmware.com/web/dp/tool/vmware-powercli.
For more information on how to install VMware PowerCLI, see the VMware PowerCLI User's Guide available at https://code.vmware.com/web/dp/tool/vmware-powercli.
- Import the Horizon PowerCLI module named
VMware.VimAutomation.HorizonView
in the Windows PowerShell session.
Use the following command to import VMware.VimAutomation.HorizonView
into the Windows PowerShell session:
Import-Module -Name VMware.VimAutomation.HorizonView
VMware.VimAutomation.HorizonView
contains the Connect-HVServer
and Disconnect-HVServer
cmdlets that you can use to connect to a Connection Server or disconnect from a Connection Server.
- Pull sample scripts from the github repository.
After you use the Connect-HVServer
cmdlet to connect to the Horizon API service of the Connection Server, you can run PowerShell scripts that invoke the Horizon APIs. For more information about Horizon APIs, see the View API Reference documentation available at https://code.vmware.com/apis/405/view.
Example scripts for the Horizon PowerCLI module are available as the VMware.Hv.Helper
module in the Modules section at https://github.com/vmware/PowerCLI-Example-Scripts.
What to do next
Use the example scripts directly or modify the scripts to suit your automation needs. Apart from example scripts, you can also develop new scripts that invoke Horizon APIs based on your needs. See, Run Example Horizon PowerCLI Scripts.