If the scripts are using "Write-Host" then the data won't be written to the "success" stream (which is what's returned in the Receive-Job).
Receive-Job, no results
I an launching local background job(s) with the Start-Job cmdlet, and -FilePath to invoke a script.
The script/job run successfully. I launch a number of these during processing. At a later point I retrieve the jobs, by ID.
If I issue the Retrieve-Job cmdlet, the results are displayed to the console, as I expect. However, I want to capture the results in a variable and process them.
The cmdlet, $J = Receive-Job -ID XX, returns $J as a System.DateTime object, but the expected output from the job is written to the console.
???
Windows for business | Windows Server | User experience | PowerShell
2 answers
Sort by: Most helpful
-
-
Limitless Technology 39,926 Reputation points
2022-05-11T07:33:35.293+00:00 Hello
Thank you for your question and reaching out.
I can understand you are having some issues \ queries related to Receive-Job not showing results.Please note that If Job isn't returning anything. Basically a job is like running a new console in the background. Any output made to that console can be retrieved with Receive-Job.
If the job uses Write-Host to produce output, Receive-Job returns $null, but the results get written to the host. However, if the job uses Write-Output to produce output in lieu of Write-Host, Receive-Job returns a string array [string[]] of the job output.
--If the reply is helpful, please Upvote and Accept as answer--