Receive-Job, no results

TreyS 166 Reputation points
2022-05-05T19:42:07.033+00:00

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
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-05-05T21:23:36.34+00:00

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

    0 comments No comments

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.