I have the following powershell script
$list = invoke-sqlcmd \'exec getOneMillionRows\' -Server...
$list | % {
GetData $_ > $_.txt
ZipTheFile $_.t
The Start-Job cmdlet allows you to run code in the background. To do what you'd ask, something like the code below should work.
foreach ($server in $servers) {
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -le 8) {
Start-Job {
Add-PSSnapin SQL
$list = invoke-sqlcmd 'exec getOneMillionRows' -Server...
...
}
} else {
$running | Wait-Job
}
Get-Job | Receive-Job
}
Hope this helps.