MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Creative Commons Attribution 4.0 International
1.93k stars 1.55k forks source link

Example doesn't provide result. #11100

Closed Pentadome closed 2 months ago

Pentadome commented 2 months ago

Type of issue

Code doesn't work

Feedback

Example 1:

$job = Start-Job -ScriptBlock {Get-Process}
Receive-Job -Job $job

In this case Receive-Job returns $null, which is unexpected given the example.

Example 2:

$job = Start-Job -ScriptBlock {Get-Service dhcp, fakeservice}
$job | Receive-Job -Keep

Cannot find any service with service name 'fakeservice'.
....

This is incorrect, powershell should not have an output here.

Fixed examples:

Example 1:

$job = Start-Job -ScriptBlock {Get-Process}
sleep 1
Receive-Job -Job $job

Example 2:

$job = Start-Job -ScriptBlock {Get-Service dhcp, fakeservice}
sleep 1
$job | Receive-Job -Keep

Cannot find any service with service name 'fakeservice'.
....

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/receive-job?view=powershell-5.1

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/5.1/Microsoft.PowerShell.Core/Receive-Job.md

Author

@sdwheeler

Document Id

041a02c8-a27e-756f-9a9d-5432bf5a52ac