Write-Host is an extremely useful cmdlet to output information to a user because this output cannot be discarded:
Write-Host "You always see me!"
# both show
# Write-Host still shows
$result = Invoke-Test
Beginning in PowerShell 5, there was a silent change in the engine though. Output emitted from Write-Host is now also controlled by the stream system, and Write-Host shares the new information stream with Write-Information.
If you wanted to hide messages emitted by Write-Host, simply redirect stream #6 to $null:
PS> $result = Invoke-Test 6>$null
For more information on streams and redirection, visit https://powershell.one/code/9.html.
ReTweet this Tip!
Powered by IDERA