Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. $jobItems = "a", "b", "c", "d", "e"
  2. $jobMax = 2
  3. $jobs = @()
  4.  
  5. $jobWork = {
  6. param ($MyInput)
  7. if ($MyInput -eq "d") {
  8. throw "an example of an error"
  9. } else {
  10. write-output "Processed $MyInput"
  11. }
  12. }
  13.  
  14. foreach ($jobItem in $jobItems) {
  15. if ($jobs.Count -le $jobMax) {
  16. $jobs += Start-Job -ScriptBlock $jobWork -ArgumentList $jobItem
  17. } else {
  18. $jobs | Wait-Job -Any
  19. }
  20. }
  21. $jobs | Wait-Job
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement