I have multiple commands in a string array that invoke SSIS packages. To take advantage of the hardware I want to run many packages at once, waiting until one completes before adding another to the fray. From looking at other similar questions on SO I think something like this would work:
cls
$commands = @()
$commands += "notepad.exe"
$commands += "notepad.exe"
$commands += "notepad.exe"
$commands += "notepad.exe"
$commands += "notepad.exe"
$commands += "notepad.exe"
foreach ($instance in $commands)
{
$running = @(Get-Job | Where-Object { $_.JobStateInfo.State -eq 'Running' })
if ($running.Count -le 2)
{
Start-Process $instance
}
else
{
$running | Wait-Job
}
Get-Job | Receive-Job
}
This does manage to open 6 notepad's, but it doesn't wait at some threshold - 2 in this example. Ideally it should wait until I close one of the notepad's (i.e. the process finishes).
Would anyone have done this before?