When I execute $job = Start-Job { dir } an then Receive-Job $job in PowerShell console I get normal output. But when I make similar .ps1 script and run it there is no output. Other commands work correctly. How do I receive job result in scripts?
$job = Start-Job { dir }
while ($job.state -ne "Completed") {}
receive-job $job
2
votes
You need to wait for the job to finish:
Start-Job { dir } | Wait-Job | Receive-Job
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more