Posted by Simon Long Feb 4, 2017
Horizon View API – Query Service
Whilst working on my Horizon View API page, trying to figure out which API calls return the data that you can see in the Horizon Administrator Console, it soon became clear that the API Query Service is used to collect a lot of the data seen within the UI. The way I managed to figure this was by analyzing a Horizon View Example Desktop Script created by Alan Renouf. So I’m going to try and document how to use the Query Service here so that other can use begin to use this really powerful tool.
Hopefully, this will be useful to you. If you have any questions, please either comment below or contact me directly. I will update this page as I learn more.
- There are few commands that we need to execute to enable the query service, I believe that these three commands will remain the same regardless of what query you are trying to run.
C:\> $ViewAPI = $global:DefaultHVServers[0].ExtensionData C:\> $query_service = New-Object "Vmware.Hv.QueryServiceService" C:\> $query = New-Object "Vmware.Hv.QueryDefinition"
- The next command needs to be modified depending on the data you are trying to capture. You can define the ‘queryEntityType‘ with any of the Queryable Data Objects.
C:\> $query.queryEntityType = 'DesktopSummaryView'
- Once the Data Object has been defined we can now run the following command. The variable name $Pool can be changed to reflect the data you are collecting.
C:\> $Pools = $query_service.QueryService_Query($ViewAPI,$query)
- Now we have the Variable defined we can start to find the data we need. In this example, I am looking to get a list Pools. Do get this information I can run the following:
C:\> $Pools.Results.DesktopSummaryData Name : CorpIT-Image-IC DisplayName : CorpIT Image v1 Enabled : True Deleting : False Type : AUTOMATED Source : INSTANT_CLONE_ENGINE UserAssignment : FLOATING AccessGroup : VMware.Hv.AccessGroupId GlobalEntitlement : VirtualCenter : VMware.Hv.VirtualCenterId ProvisioningEnabled : True NumMachines : 2 NumSessions : 0 Farm : Name : CorpIT-Image-v2 DisplayName : CorpIT Image v2 Enabled : True Deleting : False Type : AUTOMATED Source : INSTANT_CLONE_ENGINE UserAssignment : FLOATING AccessGroup : VMware.Hv.AccessGroupId GlobalEntitlement : VirtualCenter : VMware.Hv.VirtualCenterId ProvisioningEnabled : True NumMachines : 2 NumSessions : 0 Farm : Name : UEM-Pool DisplayName : UEM-Pool Enabled : True Deleting : False Type : AUTOMATED Source : VIEW_COMPOSER UserAssignment : FLOATING AccessGroup : VMware.Hv.AccessGroupId GlobalEntitlement : VirtualCenter : VMware.Hv.VirtualCenterId ProvisioningEnabled : True NumMachines : 5 NumSessions : 1 Farm : Name : WIN10-IC DisplayName : Win10 Instant Clones Enabled : True Deleting : False Type : AUTOMATED Source : INSTANT_CLONE_ENGINE UserAssignment : FLOATING AccessGroup : VMware.Hv.AccessGroupId GlobalEntitlement : VirtualCenter : VMware.Hv.VirtualCenterId ProvisioningEnabled : True NumMachines : 3 NumSessions : 1 Farm : Name : WIN10-LC DisplayName : Win10 Linked Clones Enabled : True Deleting : False Type : AUTOMATED Source : VIEW_COMPOSER UserAssignment : FLOATING AccessGroup : VMware.Hv.AccessGroupId GlobalEntitlement : VirtualCenter : VMware.Hv.VirtualCenterId ProvisioningEnabled : True NumMachines : 3 NumSessions : 0 Farm :
- If we change the ‘queryEntityType‘ to ‘MachineSumaryView’, we can then see information about our Desktops (I’ve not copied all results to this post)
C:\> $query.queryEntityType = 'MachineSummaryView' C:\> $Desktops = $query_service.QueryService_Query($ViewAPI,$query) C:\> $Desktops.Results.Base Name : UEM-002 DnsName : uem-002.lab.local User : AccessGroup : VMware.Hv.AccessGroupId Desktop : VMware.Hv.DesktopId Session : BasicState : AVAILABLE Type : MANAGED_VIRTUAL_MACHINE OperatingSystem : Windows 7 AgentVersion : 7.0.1 AgentBuildNumber : 3989057 RemoteExperienceAgentVersion : RemoteExperienceAgentBuildNumber : 24222 Name : UEM-005 DnsName : uem-005.lab.local User : AccessGroup : VMware.Hv.AccessGroupId Desktop : VMware.Hv.DesktopId Session : BasicState : AVAILABLE Type : MANAGED_VIRTUAL_MACHINE OperatingSystem : Windows 7 AgentVersion : 7.0.1 AgentBuildNumber : 3989057 RemoteExperienceAgentVersion : RemoteExperienceAgentBuildNumber : 24222 Name : UEM-004 DnsName : uem-004.lab.local User : AccessGroup : VMware.Hv.AccessGroupId Desktop : VMware.Hv.DesktopId Session : VMware.Hv.SessionId BasicState : DISCONNECTED Type : MANAGED_VIRTUAL_MACHINE OperatingSystem : Windows 7 AgentVersion : 7.0.1 AgentBuildNumber : 3989057 RemoteExperienceAgentVersion : RemoteExperienceAgentBuildNumber : 24222