Receive-Job, suppress console output

TreyS 166 Reputation points
2021-04-05T21:12:32.367+00:00

I thought this would be easy, but apparently not...

I am creating background/remote jobs in a controlling/calling script which has its own console output I want to maintain. Each time I Receive-Job, it clears the console screen and replaces it with the console output of the remote/received job.

The call, to Receive-Job assigns it to a variable, as in:
$Var = Receive-Job -ID 99

I've seen a lot of discussion about redirecting and setting $InformationPreference, but I still get the received job's output in the controlling/calling script's screen.

I would like to have the calling script just note the job completion. I deal with the content of the job later.

Thoughts?

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,625 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ian Xue 39,371 Reputation points Microsoft Vendor
    2021-04-06T02:21:46.74+00:00

    Hi,

    Try writing to the output stream using Write-Output in your job.

    Start-Job -Name job99 -ScriptBlock{           
        Write-Output "output stream"  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. MotoX80 35,501 Reputation points
    2021-04-11T01:56:52.273+00:00

    I want the Receive-Job cmdlet to be "quiet" so as to not interrupt the console output of the script creating and receiving the jobs.

    Seems to be working ok for me on PS 5.1, Can you post more of your script so that we can recreate the problem.

    cls  
    "Deleting all jobs"  
    get-job | Remove-Job  
    "Starting a remote job."  
    $jb = invoke-command -ComputerName test10b -asjob  -scriptblock {  
        "This is the job output"  
        "I ran on {0}" -f $env:computername  
    }  
    while ($jb.state -ne 'Completed') {Start-Sleep 1}  
    "Receiving"  
    $JobOutput = Receive-Job -id $jb.id   
    'Here is JobOutput'  
    $JobOutput  
    

    86519-capture.jpg

    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.