PowerCLI-Example-Scripts
PowerCLI-Example-Scripts copied to clipboard
QueryService_GetNext error on EventSummaryView problem
Hi dear all,
I would like to count unique users not on the whole infrastructure but on certain pool only. The horizon view interface only allows you to have unique users but not by pool or set of pools.
I try to use QueryService_GetNext to get all event between January 1 and December 31 based on BROKER_MACHINE_ALLOCATED filter. See code below.
It seems that with each passage of QueryService_GetNext, I receive x times allways the first 1000 and not the nexts ones (between 1000 and 2000, 2000 and 3000, etc ...). For example if i get 5500 events look on RemainingCount, i get 6 times the first 1000 events in my array. Maybe a bug or a misuse on my code?
$today = get-date
$startDate = [DateTime]::new($today.Year, 1, 1)
$endDate = [DateTime]::new($today.Year, 12, 31)
$PoolsName=@(
'poolname1-',
'poolname2-',
'poolname3-'
)
#Creation des filtres
$queryservice=new-object VMware.Hv.QueryServiceservice
#Filtre du type event
$defn=new-object VMware.Hv.QueryDefinition
$defn.queryEntityType = 'EventSummaryView'
#$defn.Limit=50
#Filtre de l'intervalle de temp
$timeFilter = new-object VMware.Hv.QueryFilterBetween -property @{'memberName'='data.time'; 'fromValue' = $startDate; 'toValue' = $endDate}
#Filtre du type d'event BROKER_MACHINE_ALLOCATED
$equalsFilter = new-object VMware.Hv.QueryFilterEquals -property @{'memberName' = 'data.eventType'; 'value' = 'BROKER_MACHINE_ALLOCATED'}
#Filtres par pool
$PoolFilter=new-object VMware.Hv.QueryFilterOr
$PoolFilters = @()
foreach ($x in $PoolsName) {
$PoolFilters += new-object VMware.Hv.QueryFilterContains -property @{'memberName' = 'data.message'; 'value' = $x}
}
$PoolFilter.Filters=$PoolFilters
#Concatenation des filtres
$andfilter=new-object vmware.hv.queryfilterand
$andfilter.filters+=$timeFilter
$andfilter.filters+=$equalsFilter
$andfilter.filters+=$PoolFilter
#Création de la définition
$defn.Filter = New-Object VMware.Hv.QueryFilterAnd -Property @{ 'filters' = $andfilter }
#Traitement de la requête
$returnList = @()
$queryResults = $queryservice.QueryService_Create($Global:objHVConnectionServer.extensionData,$defn)
$returnList += $queryResults.results
while ($queryResults -and ($queryResults.RemainingCount -gt 0)) {
$queryResults = $queryservice.QueryService_GetNext($Global:objHVConnectionServer.extensionData,$queryResults.id)
$returnList += $queryResults.results
$returnList.count
}
if ($queryResults.id) {
$queryservice.QueryService_Delete($Global:objHVConnectionServer.extensionData,$queryResults.id)
}
Disconnect-HorizonConnectionServer -HVConnectionServer $Global:objHVConnectionServer
Clear-Content $logfile
$returnList | select-object -property EventId -expandproperty data | select-object -property EventId,Time,Message -expandproperty UserId | out-string | add-content $logfile