how to get output from Receive-Job in variable – powershell trick

Powershell How To

how to get output from Receive-Job in to variable?

Based on my research is it not possible to assign output of Receive-Job to variable without writing on host, but there is any alternative which can allow us to pass all error, warning, success msg to output stream and write on host as well.

how can we do that ?

Below is command to get the $job  and receive the job output in $status1 . here we have used *>&1 which means pass all error, warning, information to output stream.

$status1=get-job -name $job | Receive-Job  *>&1

But the problem with above command is , it also print the output to host

you can use $status1 to see the outcome of the job


Here is full and tested script, you can modify as per your requirement

[gistpen id=”453″]

(Visited 4 times, 1 visits today)