I have the following powershell script
$list = invoke-sqlcmd \'exec getOneMillionRows\' -Server...
$list | % {
GetData $_ > $_.txt
ZipTheFile $_.t
Old thread but I think this could help:
$List = C:\List.txt
$Jobs = 8
Foreach ($PC in Get-Content $List)
{
Do
{
$Job = (Get-Job -State Running | measure).count
} Until ($Job -le $Jobs)
Start-Job -Name $PC -ScriptBlock { "Your command here $Using:PC" }
Get-Job -State Completed | Remove-Job
}
Wait-Job -State Running
Get-Job -State Completed | Remove-Job
Get-Job
The "Do" loop pause the "foreach" when the amount of job "running" exceed the amount of "$jobs" that is allowed to run. Than wait for the remaining to complete and show failed jobs...