February 2019
Intermediate to advanced
626 pages
15h 51m
English
RunspacePool can be used to overcome the problem of overwhelming a system. The pool can be configured with a minimum and maximum number of threads to execute at any point in time.
The RunspacePool object is created using the RunspaceFactory type, as follows:
[RunspaceFactory]::CreateRunspacePool(1, 5)
RunspacePool must be opened before it can be used. The same pool is set for each of the PowerShell instances that expects to use the pool:
$runspacePool = [RunspaceFactory]::CreateRunspacePool(1, 2)$runspacePool.Open()$jobs = 1..10 | ForEach-Object { $instance = [PowerShell]::Create().AddScript('Start-Sleep -Seconds 10') $instance.RunspacePool = $runspacePool [PSCustomObject]@{ Id = $instance.InstanceId Instance ...Read now
Unlock full access