question

TreyS avatar image
0 Votes"
TreyS asked LimitlessTechnology-2700 answered

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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).

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.