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.




