From dfd5a4e37edcf654dfde78c03a43defcef5edceb Mon Sep 17 00:00:00 2001 From: mtelvers Date: Wed, 25 Oct 2017 17:22:20 +0100 Subject: [PATCH] Fix for Find-HVMachine if no match is found in the first 1000 results If no match was found in the first 1000 results then the QueryService_GetNext() was never called as it used the length of the result array to detect the second pass through the loop --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index dd7a66c..9c0cdb8 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -6910,19 +6910,22 @@ function Find-HVMachine { $query.Filter = $andFilter } $machineList = @() + $GetNext = $false $queryResults = $query_service_helper.QueryService_Create($services, $query) do { - if ($machineList.length -ne 0) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) } + if ($GetNext) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) } $machineList += $queryResults.results + $GetNext = $true } while ($queryResults.remainingCount -gt 0) $query_service_helper.QueryService_Delete($services, $queryResults.id) } if ($wildcard -or [string]::IsNullOrEmpty($machineList)) { $query.Filter = $null $machineList = @() + $GetNext = $false $queryResults = $query_service_helper.QueryService_Create($services,$query) do { - if ($machineList.length -ne 0) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) } + if ($GetNext) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) } $strFilterSet = @() foreach ($setting in $machineSelectors.Keys) { if ($null -ne $params[$setting]) { @@ -6936,6 +6939,7 @@ function Find-HVMachine { $whereClause = [string]::Join(' -and ', $strFilterSet) $scriptBlock = [Scriptblock]::Create($whereClause) $machineList += $queryResults.results | where $scriptBlock + $GetNext = $true } while ($queryResults.remainingCount -gt 0) $query_service_helper.QueryService_Delete($services, $queryResults.id) }