I have been using the Foreach-object -Parallel for quite some time now, and are generally happy with it.
But i would like to name the childjobs, with a name of my choosing.
The code will generate a set of childjobs called “Job1, Job2, Job3, etc”
If you want to use -Parallel then it makes little sense to do them as jobs. That is the purpose of parallel to run them all at once. If you’d prefer jobs with custom names, just handle the jobs yourself and forego -Parallel
$joblist = @("Server1","Server2","Server3") | ForEach-Object {
Start-Job -Name $_ -ScriptBlock {
Param($Variable)
# code that you would've been running in the foreach-object originally
"$variable is what was passed into argumentlist"
} -ArgumentList $_
}
$joblist | Get-Job
And … depending on the amount of jobs you usally create I’d say it’s a little bit like the difference between cattle and pets. The ones you give names and take care of individually. While the others are a kind of faceless homogenous mass you actually don’t see as individual beings.
So i am using the Jobs to pull some info from all our SQL servers, but want to limit it to 10-20 concurrent tasks (therefor the -Parallel & -ThrottleLimit 10 - might be incorrect, but it was the best example i could get to work.)
Sometimes the query for a given SQL server fail for whatever reason, and the solution is then to go through the childjobs that have a failed state, and see what happened.
It would be nice to have the job named as the SQL instance, so that i can just by looking at the name, see what server it have failed on - its not critical at all, but had hoped it would be possible
I luckily got a proper error handling in place, and its nicely logged to a database - so i agree on that part
But had still hoped, that i could name the child jobs
Anyways - thanks for the help! Its greatly appreciated!