Skip to content

Instantly share code, notes, and snippets.

@exchange12rocks
Created October 10, 2016 00:10
Show Gist options
  • Save exchange12rocks/916cf7190205e5eb08f77b34bf57ca71 to your computer and use it in GitHub Desktop.
Save exchange12rocks/916cf7190205e5eb08f77b34bf57ca71 to your computer and use it in GitHub Desktop.
$maxConcurrentJobs = 100 #Max. number of simultaneously running jobs
foreach($Object in $Objects) { #Where $Objects is a collection of objects to process. It may be a computers list, for example.
$Check = $false #Variable to allow endless looping until the number of running jobs will be less than $maxConcurrentJobs.
while ($Check -eq $false) {
if ((Get-Job -State 'Running').Count -lt $maxConcurrentJobs) {
$ScriptBlock = {
#Insert the code of your workload here
}
Start-Job -ScriptBlock $ScriptBlock
$Check = $true #To stop endless looping and proceed to the next object in the list.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment