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
This commit is contained in:
@@ -6910,19 +6910,22 @@ function Find-HVMachine {
|
|||||||
$query.Filter = $andFilter
|
$query.Filter = $andFilter
|
||||||
}
|
}
|
||||||
$machineList = @()
|
$machineList = @()
|
||||||
|
$GetNext = $false
|
||||||
$queryResults = $query_service_helper.QueryService_Create($services, $query)
|
$queryResults = $query_service_helper.QueryService_Create($services, $query)
|
||||||
do {
|
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
|
$machineList += $queryResults.results
|
||||||
|
$GetNext = $true
|
||||||
} while ($queryResults.remainingCount -gt 0)
|
} while ($queryResults.remainingCount -gt 0)
|
||||||
$query_service_helper.QueryService_Delete($services, $queryResults.id)
|
$query_service_helper.QueryService_Delete($services, $queryResults.id)
|
||||||
}
|
}
|
||||||
if ($wildcard -or [string]::IsNullOrEmpty($machineList)) {
|
if ($wildcard -or [string]::IsNullOrEmpty($machineList)) {
|
||||||
$query.Filter = $null
|
$query.Filter = $null
|
||||||
$machineList = @()
|
$machineList = @()
|
||||||
|
$GetNext = $false
|
||||||
$queryResults = $query_service_helper.QueryService_Create($services,$query)
|
$queryResults = $query_service_helper.QueryService_Create($services,$query)
|
||||||
do {
|
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 = @()
|
$strFilterSet = @()
|
||||||
foreach ($setting in $machineSelectors.Keys) {
|
foreach ($setting in $machineSelectors.Keys) {
|
||||||
if ($null -ne $params[$setting]) {
|
if ($null -ne $params[$setting]) {
|
||||||
@@ -6936,6 +6939,7 @@ function Find-HVMachine {
|
|||||||
$whereClause = [string]::Join(' -and ', $strFilterSet)
|
$whereClause = [string]::Join(' -and ', $strFilterSet)
|
||||||
$scriptBlock = [Scriptblock]::Create($whereClause)
|
$scriptBlock = [Scriptblock]::Create($whereClause)
|
||||||
$machineList += $queryResults.results | where $scriptBlock
|
$machineList += $queryResults.results | where $scriptBlock
|
||||||
|
$GetNext = $true
|
||||||
} while ($queryResults.remainingCount -gt 0)
|
} while ($queryResults.remainingCount -gt 0)
|
||||||
$query_service_helper.QueryService_Delete($services, $queryResults.id)
|
$query_service_helper.QueryService_Delete($services, $queryResults.id)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user