coming soon
Tag: horizon api
Part 2: Connection to the Horizon API
To access the Horizon API we need a credential that has read access. Let’s begin …
What I usually do in this scenario is creating an account and saving the password as a secure string in the same location as the script. This method is more secure then passing it along in clear text.
'<password>' | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File ./secure-password.txt
You only need to do this again when your password has changed. Next we will create a credential object that we can use to connect to the Horizon API.
$svc_account_username = '<username>@<domain>'
$svc_account_password = get-content .\secure-password.txt | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList ($svc_account_username, $svc_account_password)
The next part is actually connecting to the Horizon API using the credential and storing the output in a variable:
$services = Open-HVConnection -HVServer <connection server fully qualified domain name> -Credential $Credential
Last piece of the puzzle is to close the connection and we are done for part 2.
Close-HVConnection -HVServer <connection server fully qualified domain name>
In Part 3 we will have a look at what we received.
In the next series you will see how we can use the VMware Horizon API in combination with some Powershell modules to document the environment.
Part 1: Installing the necessary Tools and Powershell modules
First we need to install Powershell. There or several ways to do so but I tend to turn to Homebrew whenever I can.
Brew Install --cask powershell
PScribo: PScribo provides a set of functions that make it easy to create a document-like structure within Powershell scripts without having to be concerned with handling output formatting or supporting multiple output formats.
Install-Module PScribo
Next we will need the VMware modules. With the following command you get a list of the possibilities:
Find-Module -name VMware.*
We only need the one for VMware Horizon for now, let’s install it:
Install-Module VMware.VimAutomation.HorizonView
That’s all for now. In part 2 of the series we will set-up the credential and connect to the Horizon API.