With the new Horizon View Module you will be able to access 100% of the public API meaning if its available as a feature in the UI then the likelihood is that you will be able to automate it and being able to use these from a scripting host with all the other PowerCLI features, your own workstation or a jump box makes this very convenient.

What do I need?

First of all, you will need to install PowerCLI 6.5 R1 as found here

You will also need to access the new Horizon View API Documentation here

I also highly recommend checking out the great advanced functions the Horizon View team has put in the PowerCLI-Example-Scripts repo which will make life much easier as you will see in a later post in this series.

Lets get started…

Get-Module –ListAvailable VMware*Horizon* | Import-Module Get-Command –Module Vmware.VimAutomation.HorizonView

Once you have installed PowerCLI 6.5 R1 and launched it you will see that if we import the module and list the commands all we have is 2 cmdlets to work with, well that isn’t much use is it?! or is it?



Clearly the first thing we need to do is connect to the Horizon View server using our credentials, you can do this as follows:

As I mentioned before, you have access to 100% of the API so now we are connected lets take a look at the connection variable which gets created automatically and holds the keys to the kingdom, or in this case the entire API. You will see that a global variable gets created called DefaultHVServers, this stores the connection information to the connected Horizon View Servers and can be access with $global:DefaultHVServers as seen below

This gives us a little more interesting information but the real fun stuff is under Extensiondata so lets take a look at that:

If you have taken a look at the Horizon View documentation as linked at the start of this post then you will start to recognize some of these areas, the extensiondata holds the access to the entire API, lets see how we might use this. So now we have got this far and understand how to access the API lets take a simple use case and see what we can do.

My use case is that I want to programmatically check the vSphere components section to ensure they are all connected OK, I might then take this script once I have written it and check it on a periodic basis through some monitoring software to ensure my Horizon environment is healthy, a simple use case to get us started. The screen shot below shows the type of data I want to get back:

First of all lets look through the extensiondata for something that might look right:

Great, we have found a property called VirtualCenterHealth, lets dive deeper into this with the PowerShell command Get-Member, this will tell us all the properties and methods we can use with this API:

We can see that we have a number of methods and 2 properties, one of the methods looks like what we need VirtualCenterHealth_List, lets call the method on this object and see what information it returns:

This looks like exactly the type of data we need, in fact we can see both the HostData and the DatastoreData from our screenshots so lets take a look at each of these:

Perfect, this is exactly what we are looking for, we can see that the accessible property is true and the status property is connected so we are all good and we have the information we need. One thing we can do is now make this easier to access by wrapping this code into a simple function which we can save, share and re-use in the future as shown below:

Conclusion

This may have been a very simple example but its enough to get us going and has the fundamentals that we can use when exposing the Horizon View API, in a future post I will show you how the Horizon View team has used a similar practice to create some great advanced functions which will take the hard work out of you needing to do this for some of the common areas.