Hey guys. I've just recently started working with Powershell, mostly because of its capabilities with multi-threading.
I've got a script that uses IP ranges to pull each system's hostname and MAC address (using nbtstat and nslookup). It works when I run the script as a single job. But when I try to run multiple threads as background jobs, they seem to interfere with one another. Each job starts, but it only fully generates the output for the last job. It seems like as each successive job starts, it cuts off the former.
Are there some limitations to running multiple background jobs that I should be aware of? Thanks in advance.
by Jason_Yoder_MCT at 2012-11-13 11:08:12
Anyway I can look at the code?
by the_hutch at 2012-11-13 13:16:16
I figured out what I was doing wrong. For each job, the functionality depended on me piping an array ($Range1) into a ForEach loop. The problem was, I wasn't passing the array correctly to the scriptblock.
I was doing this: Start-Job -ScriptBlock $job1 -ArgumentList ($Range1)
Instead of this: Start-Job -ScriptBlock $job1 -ArgumentList (,$Range1)
The difference being the comma at the beginning of the passed value. Without the comma, it just passes the first value in the array, instead of the entire thing. That's why I thought the job was starting in each case, but not finishing. The script seems to be working now. Thanks for the response.
The topic ‘Background Jobs Interfering with one another’ is closed to new replies.