I recently answered a forums post from someone who was wanting to make PowerShell’s error messages go away. That is, he was fine with the errors occurring, but wanted to suppress their output in the console window. Easy, once you know how!
Errors – and anything output by Write-Error – wind up in a special pipeline, which is conveniently called the Error pipeline. When this pipeline dumps to Out-Host, it does so with a red foreground color, making your errors stand out like a bad 3rd-grade essay on “what I did this summer.”
There are other special pipelines, too: Debug and Warning, to name a couple. All of them can be “pinched off” using a special “valve” variable: $ErrorActionPreference, $DebugPreference, and $WarningPreference for this discussion. Set them to “Continue” and they allow output out of the pipeline and onto the screen; set them to “SilentlyContinue” and the close off the pipeline, letting no messages escape. Set them to “Inquire” and they’ll actually ask you if you want to continue… just after they display the output anyway.
Now that last bit (“Inquire”) might seem silly. But it’s not: Imagine filling your script with Write-Debug statements, each one outputting some information about a script’s status. Set $DebugPreference to “Inquire” and you’ll not only see each debug line, but your script will pause while you decide whether or not to continue. Kinda cool, and it’s not dissimilar to the way the built-in PowerShell debugger works, in fact.
So play with your pipelines: Turn ‘em on, turn ‘em off, make the shell shout out or shut up, all at your $Preference.