Receive-Job, no results

TreyS 166 Reputation points

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,460 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points

    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,511 Reputation points


    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