vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
753 stars 603 forks source link

exceed limit of open queries #467

Open MarkoKastner84 opened 3 years ago

MarkoKastner84 commented 3 years ago

Due to issue #466 we cant get a complete list of all our client anymore.

our first workaround: get a list of all pools and for each pool: get a list of machines of that pool - join them all together getting clients of an empty pool raises an error that we ignore (Due to issue #466)

This way i get the first 2570 machines we have, but after that i get an error when asking for the clients of the next pool:

Find-HVMachine : Exception calling "QueryService_Create" with "2" argument(s): "ExceptionType : VMware.Hv.InvalidState
ErrorMessage : Creating a new query would exceed the limit of open queries allowed
Id : "
At C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.HV.Helper.psm1:7707 char:18

second workaround: we do it as the first workaround, but disconnect and reconnect to the HVServer every 4 Pools, because even asking for the clients of 10 pools can exceed the maximum limit of opened queries

$counter = 0 $pools = Get-HVPool $VMs = @() foreach($pool in $pools){ try{ if($counter -eq 5){ Disconnect-HVServer * -Force -Confirm:$false Connect-HVServer $HVserver -Force -User "someuser" -Password "somepassword" $counter = 0 } $counter +=1 $Clients = $null $Clients = Get-HVMachineSummary -PoolName $pool.Base.Name $VMs = @($VMs)+$clients

}catch{
    write-host ("pool with errors: " + $pool.Base.Name)
}

}

Because we ask for the clients of each pool seperately pool by pool, i dont get why this should exceed the maximum number of queries. Seems like the queries are not closed after the result was received and Get-HVMachineSummary has finished? Or is there a query for each client that is found and we have more clients than supported?

nthoman commented 2 years ago

How do you close the open queries?

I was using your example here to automate some DR Testing and entitling users to new machines we bring up. https://github.com/Magneet/Various_Scripts/blob/master/add_and_entitle_desktop.ps1

sdewyser commented 2 years ago

In the Get-HVMachineSummary or function Find-HVMachine function you can close the query service after you assign the result to a variable with the following command:

$query_service_helper.QueryService_Delete($services, $queryResults.id)