Easy one for some gurus.
I’m trying to replace an existing Windows script with a powershell equivalent to run across multiple files and folders and execute scripts with sequencing rules. The recursion of directories, and sequencing is all working and now I just want to execute the jobs, detect when completed, ideally detect errors to abort the process, and log the output to a common log file.
If I just start a process, it runs fine. But if I start a job using a variable, then:
- The job is listed as "$TheJob" from Get-Job
- I don't get any output from Receive-Job.
Start-Job -ScriptBlock {D:\MyWork\Powershell\10-Setup\20-LoadControlData\10-LoadControlData5.ps1} $TheJob = "D:\MyWork\Powershell\10-Setup\20-LoadControlData\10-LoadControlData5.ps1" Start-Job -ScriptBlock { $TheJob } get-job | Wait-Job get-job | Receive-JobSee below, Hello World is output only once.
Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 62 Job62 BackgroundJob Running True localhost D:\MyWork\Powershell\1... 64 Job64 BackgroundJob Running True localhost $TheJob 62 Job62 BackgroundJob Completed True localhost D:\MyWork\Powershell\1... 64 Job64 BackgroundJob Completed True localhost $TheJob Hello world!