The Receive-Job command

Receive-Job is used to retrieve data from a job. Receive-Job may be both as a script runs and when the script is finished. If Receive-Job is run before a job is finished, any existing values will be returned. Running Receive-Job again will get any new values that have been added, not previously filesystem, which retrieved values. This is shown in the following example:

PS> $job = Start-Job { 1..10 | ForEach-Object { $_; Start-Sleep -Seconds 2 } }
>> Write-Host 'Sleeping 2'
>> Start-Sleep -Seconds 2
>> $job | Receive-Job
>> Write-Host 'Sleeping 5'
>> Start-Sleep -Seconds 5
>> $job | Receive-Job

Sleeping 2
1
Sleeping 5
2
3
4

The remaining results will be available to Receive-Job as they are returned, or when the job has completed.

The Wait parameter of Receive-Job will receive data from the job as it becomes available and send it to the output pipeline. Receive-Job, along with the Wait parameter, may be useful when Start-Job is running a 32-bit process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.94.152