Receive-Job duplicates Write-Host output
Starting in PowerShell 5.1, if a background job uses Write-Host, the Receive-Job cmdlet shows each line of output twice.
# Steps to Reproduce
1. Run this command: `Start-Job { 1..10 | % { Start-Sleep -Milliseconds 10 ; Write-Host $_ } } | Wait-Job | Receive-Job`
2. Note the duplicate numbers. This error does not happen in Powershell 6.0.4.

2 comments
-
Aaron Jensen commented
This also affects PowerShell Core 6.1: https://github.com/PowerShell/PowerShell/issues/7814
-
Aaron Jensen commented
It looks like this is related to the $InformationPreference variable. If it is set to "Continue", when Receive-Job runs, it duplicates the output.
One workaround is to set the InformationAction parameter on Receive-Job to "SilentlyContinue":
Start-Job { 1..10 | % { Start-Sleep -Milliseconds 10 ; Write-Host $_ } } | Wait-Job | Receive-Job -InformationAction SilentlyContinue