4

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?

Dmitry Fedorkov
  • 145
  • 1
  • 1
  • 5

1 Answers1

7

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.

Dmitry Fedorkov
  • 145
  • 1
  • 1
  • 5
sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
  • So I try: `$job = Start-Job { dir }` `Receive-Job $job` $job.hasMoreData is true, but output is empty. – Dmitry Fedorkov Jun 19 '12 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. – sysadmin1138 Jun 19 '12 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. – Dmitry Fedorkov Jun 20 '12 at 08:11