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
  • kyle

    Have you found a way to query the health status of vCenter as displayed in View Admin? i.e. Green or Red in View Admin = something/somewhere in the API? I spent a while poking and found the VMware.HV.VirtualCenterHealth stuff in the API but none of its methods or properties seemed to contain the current status, same for the security and connection server objects.

    Since there is no log for the services changing status and Horizon Events doesn’t track them either, I was hoping i could pull the status through the API and maybe from there figure out how to generate an alert when my services changed to Red.

  • Good question. This would be really handy. Let me see what I can find.

  • I can’t see anything either. I’ll see if I can ask internally.

  • kyle

    Let me know if you find any answers. I’ve got this tagged to work on if i can ever find the values in the API.

  • I’ve head back from the Dev team:

    They can use these health VIEW APIs (ADDomainHealth, CertificateSSOConnectorHealth, ConnectionServerHealth, EventDataBaseHealth, FarmHealth, PodHealth, SamlAuthenticatorHealth, SecurityServerHealth, ViewComposerHealth, VirtualCenterHealth ) and able to generate alerts via powerCLI.

    I’ve not had any spare time to test it yet though.

  • kyle

    $global.DefaultHVServers.extensiondata.VirtualCenterHealth.VirtualCenterHealth_LIST().connectionserverdata has some Status values that look promising. Interestingly enough 3 of my ConnServers are showing STATUS_UP while one is STATUS_DOWN. But at least i think i’m on the right track now.

    https://vdc-repo.vmware.com/vmwb-repository/dcr-public/f004a27f-6843-4efb-9177-fa2e04fda984/5db23088-04c6-41be-9f6d-c293201ceaa9/doc/vdi.health.VirtualCenterHealth.ConnectionServerConnectionData.html

 
Get Adobe Flash player