{"id":176,"date":"2007-08-03T01:09:47","date_gmt":"2007-08-03T09:09:47","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/08\/03\/shut-up-shell\/"},"modified":"2007-08-03T01:09:47","modified_gmt":"2007-08-03T09:09:47","slug":"shut-up-shell","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/08\/03\/shut-up-shell\/","title":{"rendered":"Shut up, shell!"},"content":{"rendered":"<p>I recently answered a forums post from someone who was wanting to make PowerShell&#8217;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!<\/p>\n<p>Errors &#8211; and anything output by Write-Error &#8211; 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 &#8220;what I did this summer.&#8221; <\/p>\n<p>There are other special pipelines, too: Debug and Warning, to name a couple. All of them can be &#8220;pinched off&#8221; using a special &#8220;valve&#8221; variable: $ErrorActionPreference, $DebugPreference, and $WarningPreference for this discussion. Set them to &#8220;Continue&#8221; and they allow output out of the pipeline and onto the screen; set them to &#8220;SilentlyContinue&#8221; and the close off the pipeline, letting no messages escape. Set them to &#8220;Inquire&#8221; and they&#8217;ll actually ask you if you want to continue&#8230; just after they display the output anyway.<\/p>\n<p>Now that last bit (&#8220;Inquire&#8221;) might seem silly. But it&#8217;s not: Imagine filling your script with Write-Debug statements, each one outputting some information about a script&#8217;s status. Set $DebugPreference to &#8220;Inquire&#8221; and you&#8217;ll not only see each debug line, but your script will pause while you decide whether or not to continue. Kinda cool, and it&#8217;s not dissimilar to the way the built-in PowerShell debugger works, in fact.<\/p>\n<p>So play with your pipelines: Turn &#8216;em on, turn &#8216;em off, make the shell shout out or shut up, all at your $Preference.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently answered a forums post from someone who was wanting to make PowerShell&#8217;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 &#8211; and anything output by Write-Error &#8211; wind up in a special [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}