The Query Service is a generic service for listing or filtering large sets of results.
The query service supports two types of querying: paged and virtual list.
Note: only 5 active paged queries can exist at a time on a single connection. Attempting to create additional queries when that limit is reached will result in an error.
The Query Service provides the ability to filter on properties of the resulting data object. The exact list of supported filters is detailed in the left pane. Further restrictions on which properties can be used as part of a filter will be specified as part of the documentation on that specific data object or the specific filter. Not all fields can be used to filter. In particular, the "id" field of any data object cannot be used as a field to filter upon.
There are various types of controls that can be used to control the result set. These are documented in the QueryDefinition.
Here are a few examples of using the Query Service.
This example demonstrates how to handle the results from the QueryResults object. This will be omitted in the remaining examples.
$queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'FarmSummaryView' $queryResults = $queryService.QueryService_Create($hvServices, $defn) # Handle results try { while ($queryResults.results -ne $null) { foreach ($result in $queryResults.Results) { [VMware.Hvi.FarmSummaryView]$farmSummaryView = $result # Do work. } # Fetch next page if ($queryResults.id -eq $null) { break; } $queryResults = $queryService.QueryService_GetNext($hvServices, $queryResults.id) } } finally { if ($queryResults.id -ne $null) { $queryService.QueryService_Delete($hvServices, $queryResults.id) } }
$queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'RDSServerInfo' defn.setFilter = New-Object VMware.Hv.QueryFilterEquals -property @{'memberName'='settings.enabled'; 'value' ='$true'} $queryResults = $queryService.QueryService_Create($hvServices, $defn) # Handle results
$queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'DesktopSummaryView' $defn.sortBy = 'desktopSummaryData.name' $defn.sortDescending = $true QueryResults queryResults = queryService.create($hvServices, $defn); # Handle results
This example will retrieve the third page of 10 ApplicationInfo objects, without needing to access the first two pages.
$queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'ApplicationInfo' $defn.startingOffset = 20 $defn.limit = 10 $queryResults = $queryService.QueryService_Query($hvServices, $defn) # Handle results. Don't need to delete query as there is no server side clean-up needed.
QueryDefinition defn = new QueryDefinition(); $queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'PersistentDiskInfo' defn.setFilter = New-Object VMware.Hv.QueryFilterStartsWith -property @{'memberName'='general.name'; 'value' ='a'} $count = $queryService.QueryService_GetCount($hvServices, $defn)