Intro
I have done a lot of deep dives but just like the VMware{Code} session I did at VMworld I think it’s time to go back to the basics on how to work with the Horizon api’s from PowerCLI. First up is connecting to a Connection server and disconnecting. I will be showing various ways to do but the new and secure one is the best for me since that’s also usable when you want to schedule scripts.
The easy way
The easiest wat to connect is by using the connect-hvserver SERVERNAME
connect-hvserver pod1cbr1
This will give you a nice credentials popup.
The Unsecure way
The previous way that I used was by using the -user, -pass and maybe the -domain parameters.
connect-hvserver pod1cbr1 -user m_wouter@magneet -pass Password
The ‘new’ and secure way
Since one of the latest updates it is also possible to use a credential object. We found this out during the Hackathon @VMworld US that it is possible. It will use the good old credentials function from Powershell like in this post from 2008. First you’ll need to make a file with the encrypted password. Big thanks to Ariel & Edgar 🙂 check this for the vDocumentation script.
read-host -assecurestring | convertfrom-securestring | out-file password.txt
The next two lines I will combine into one, just because I can.
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "magneet\m_wouter",(get-content .\password.txt | ConvertTo-SecureString)
Doing it in two lines is also possible and might make it a bit easier to read
$pass= get-content .\password.txt | ConvertTo-SecureString $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "magneet\m_wouter", $pass
And then it’s time to connect
connect-hvserver -server pod1cbr1 -cred $cred
That’s easy right?
Connect to the api’s
There’s a little bit more to it so you can actually use the api’s. First we need to put the session into a variable. I always use a number so it’s easy to separate my various pods.
$hvserver1=connect-hvserver -server pod1cbr1 -cred $cred
Next up is actually making the services visible. Again I added the number for when I am working with multiple pod’s.
$Services1= $hvServer1.ExtensionData
And a quick look at the available services which I will explain in a next blog post.
Disconnecting
If you are connected to a single Connection server this is easy, just a disconnect-hvserver is enough.
disconnect-hvserver
Or without confirmation, this is a standard powershell thing.
disconnect-hvserver -confirm:$false
This will not work when you are connected to multiple Pod’s so you’ll need to specify the server you are connected to.
disconnect-hvserver -server pod2cbr1 -confirm:$false
The End
Next time I will go into some of the things you can do with the services I quickly showed you.