5

When I run command Start-Job {dir} in PowerShell I get output

Id Name State HasMoreData Location Command -- ---- ----- ----------- -------- ------- 43 Job43 Running True localhost dir 

How can I make this job write its output to console?

1 Answer 1

8

That's handled through the receive-job cmdlet.

$job = Start-Job { dir } Receive-Job $job 

You only get data if HasMoreData is true on your get-job output. This will return as an array, with one line of text per array-element.

help about_jobs will give you quite a bit of detail about how to interact with jobs in general.

3
  • So I try: $job = Start-Job { dir } Receive-Job $job $job.hasMoreData is true, but output is empty. Commented Jun 19, 2012 at 14:36
  • @DmitryFedorkov You seem to be missing -job $job in your code-fragment, that's needed. The command help receive-job -examples will give you very useful information. Commented Jun 19, 2012 at 14:42
  • It does not matter, because argument -Job has position 1. My problem turned out in PowerGUI that for some reason does not work correctly. Anyway, thanks for help. Commented Jun 20, 2012 at 8:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.