Answered by:
Use of Child JOB

Question
-
Hi All,
I was just trying to learn Job concepts in Powershell and what I don't understand is Child Job even after multiple re-read. Tried googling but didn't get convincing explanation.
Why is that getting created and what is the use of it? I found that I can use either master or child. If I use Child, then data stored in Master Job also getting cleared. I know -keep can be used to retain copy, but stil I don't understand why there is child Job created ?
- Edited by PrajithK Wednesday, April 4, 2018 5:21 AM
Wednesday, April 4, 2018 5:14 AM
Answers
-
Hi,
I am still a powershell newbie (well, I can do many stuffs alone though), so I cant tell u the background of this use in some expert-ish way.
So I give u a practical use - from my point of view - still, it is an NEWBIE view.
When u create a job, which has more entries (multiple computernames), it will register as a single job with one ID.
$Computers = " NormalComputer nonExistComputer AccessDeniedComputer " $sblok = { ... } invoke-command -ComputerName $Computers -ScriptBlock $sblok -AsJob
JobStateInfo : Failed Finished : System.Threading.ManualResetEvent InstanceId : f0ef854c-85f0-429b-a71d-2bd0bf40f7d6 Id : 9 Name : Job9 ChildJobs : {Job10, Job11, Job12}
The (failed) job will contain 3 ChildJobs (each for one computer)
Name : Job9 (master) JobStateInfo : Failed State : Failed Name : Job10 (normalComputer) JobStateInfo : Completed State : Completed Name : Job11 (AccessDeniedComputer) JobStateInfo : Failed State : Failed Name : Job12 JobStateInfo : Failed State : Failed
Why is it good for me? Well, when I try to run against hundreds machines (for example I need to check services), I need to know where the possible raised error comes from.
When something bad happen (even one computer is offline), the masterjob result will be FAILED. So I lookup at childjobs to see which one failed and what is the reason.
There are 2 sources of errors when using jobs (job and remote computer). There I check childjobs status to get the correct result from my script. I cant depend on master job result, because it will be Completed without error, even if remotecomputer raises some red text :) (checking for nonsexist service forexample)
get-job -id 18 |fl id,name,psjobtypename,state Id : 18 Name : Job18 PSJobTypeName : RemoteJob State : Completed
- Marked as answer by PrajithK Thursday, April 26, 2018 2:04 PM
Wednesday, April 4, 2018 6:14 AM
All replies
-
Hi,
I am still a powershell newbie (well, I can do many stuffs alone though), so I cant tell u the background of this use in some expert-ish way.
So I give u a practical use - from my point of view - still, it is an NEWBIE view.
When u create a job, which has more entries (multiple computernames), it will register as a single job with one ID.
$Computers = " NormalComputer nonExistComputer AccessDeniedComputer " $sblok = { ... } invoke-command -ComputerName $Computers -ScriptBlock $sblok -AsJob
JobStateInfo : Failed Finished : System.Threading.ManualResetEvent InstanceId : f0ef854c-85f0-429b-a71d-2bd0bf40f7d6 Id : 9 Name : Job9 ChildJobs : {Job10, Job11, Job12}
The (failed) job will contain 3 ChildJobs (each for one computer)
Name : Job9 (master) JobStateInfo : Failed State : Failed Name : Job10 (normalComputer) JobStateInfo : Completed State : Completed Name : Job11 (AccessDeniedComputer) JobStateInfo : Failed State : Failed Name : Job12 JobStateInfo : Failed State : Failed
Why is it good for me? Well, when I try to run against hundreds machines (for example I need to check services), I need to know where the possible raised error comes from.
When something bad happen (even one computer is offline), the masterjob result will be FAILED. So I lookup at childjobs to see which one failed and what is the reason.
There are 2 sources of errors when using jobs (job and remote computer). There I check childjobs status to get the correct result from my script. I cant depend on master job result, because it will be Completed without error, even if remotecomputer raises some red text :) (checking for nonsexist service forexample)
get-job -id 18 |fl id,name,psjobtypename,state Id : 18 Name : Job18 PSJobTypeName : RemoteJob State : Completed
- Marked as answer by PrajithK Thursday, April 26, 2018 2:04 PM
Wednesday, April 4, 2018 6:14 AM -
A full and accurate explanation of child jobs is here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_job_details?view=powershell-6
\_(ツ)_/
- Proposed as answer by PRASOON KARUNAN V Wednesday, April 4, 2018 5:38 PM
Wednesday, April 4, 2018 7:10 AM -
Ah, my newbie view is not far from official explanation, good to see :)Wednesday, April 4, 2018 7:46 AM
-
Thanks for the reply :-)Thursday, April 26, 2018 2:05 PM
-
Thanks for the reply :-)Thursday, April 26, 2018 2:05 PM