Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $jobItems = "a", "b", "c", "d", "e"
- $jobMax = 2
- $jobs = @()
- $jobWork = {
- param ($MyInput)
- if ($MyInput -eq "d") {
- throw "an example of an error"
- } else {
- write-output "Processed $MyInput"
- }
- }
- foreach ($jobItem in $jobItems) {
- if ($jobs.Count -le $jobMax) {
- $jobs += Start-Job -ScriptBlock $jobWork -ArgumentList $jobItem
- } else {
- $jobs | Wait-Job -Any
- }
- }
- $jobs | Wait-Job
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement