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
Simon Long

View Comments

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

  • Thanks for this information, I am able to connect and use the examples! How would I be able to use this now to be able to reset or remove a virtual desktop using the API, for example a floating pool machine is in error and I want to automate the removal of it? I found the commands in the API, but I am confused on how to do this - any ideas?..Thanks!

Share
Published by
Simon Long

Recent Posts

Google Cloud VMware Engine @ VMworld 2021

Another VMworld is upon us!!! Sadly, it's only virtual again this year. However, that does…

3 years ago

Google Cloud VMware Engine – Learning Resources

As part of my recent move to Google, I'm working on quickly getting up to…

3 years ago

Hey Google!

I am delighted to announce the next chapter in my career. Today is my first…

3 years ago

EP13 – Defending Remotely

In episode thirteen of The VCDX Podcast, I am joined by two special guests who…

3 years ago

Getting Started With Oracle Cloud VMware Solution (OCVS) – Migrating Workloads Using VMware HCX

In my recent ‘Getting started with Oracle Cloud VMware Solution (OVCS)’ post; Getting Started With…

3 years ago

Getting Started With Oracle Cloud VMware Solution (OCVS) – Connecting To An On-Premises Environment

In my recent ‘Getting started with Oracle Cloud VMware Solution (OVCS)’ post; Getting Started With…

3 years ago