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 3 times, 1 visits today)

By Arun Sabale

Arun is a Solution Architect on enterprise client management with more than 14 years of experience in IT. Arun Sabale is Blogger and tech enthusiast. His main focus is on Azure cloud infra, Cloud automation with powershell, python, ARM terraform and all cloud infra services like compute, storage, network, automation, function api etc... LinkedIN - https://www.linkedin.com/in/arun-sabale/