{"id":86406,"date":"2018-07-10T00:34:47","date_gmt":"2018-07-10T08:34:47","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/koryt\/?p=665"},"modified":"2019-10-09T11:31:23","modified_gmt":"2019-10-09T19:31:23","slug":"powershell-powertip-what-you-should-know-about-streams","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powershell-powertip-what-you-should-know-about-streams\/","title":{"rendered":"PowerShell PowerTip: What you should know about streams"},"content":{"rendered":"<p>PowerShell has a concept called Streams, which are the different places data can go (output, error, verbose, etc). You usually don&#8217;t have to worry too much about these streams if you&#8217;re just writing simple scripts, but it helps a ton to know:<\/p>\n<ol>\n<li>All streams are separate even if they all appear to be coming to the console for you.<\/li>\n<li>Assignment operators (like &#8220;=&#8221;) only look at the output stream.<\/li>\n<li>If you don&#8217;t tell PowerShell where to put data (such as just typing get-process) it defaults to the output stream.<\/li>\n<\/ol>\n<p>What this means for you, as users, is that you can get a non-terminating error, and still do work on the successful output. Take a look at this:<\/p>\n<pre class=\"lang:ps decode:true\">$procs = get-process POWERPNT, powershell_ise, FAKE, audiodg\r\n\r\nWrite-host \"Procs contains:\"\r\n$procs.name<\/pre>\n<pre class=\"lang:default decode:true \">get-process : Cannot find a process with the name \"FAKE\". Verify the process name and call the cmdlet again.\r\nAt line:1 char:10\r\n+ $procs = get-process POWERPNT, powershell_ise, FAKE, audiodg\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : ObjectNotFound: (FAKE:String) [Get-Process], ProcessCommandException\r\n+ FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand\r\n\r\nProcs contains:\r\naudiodg\r\nPOWERPNT\r\npowershell_ise<\/pre>\n<p>Notice that even though I received an error for the process &#8220;FAKE&#8221;, only the non-errors were present in $procs. Using some basic error handling we could clean that up, hide the error message and log out what we didn&#8217;t find.<\/p>\n<p>If you want to learn more about these streams, let me know and I can write a more detailed blog post.<\/p>\n<p>Hope that helps, tune in more often to get short and sweet PowerTips!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell has a concept called Streams, which are the different places data can go (output, error, verbose, etc). You usually don&#8217;t have to worry too much about these streams if you&#8217;re just writing simple scripts, but it helps a ton to know: All streams are separate even if they all appear to be coming to [&hellip;]<\/p>\n","protected":false},"author":7300,"featured_media":87096,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1738],"tags":[2221,2125,377,356],"class_list":["post-86406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-kory-thacher","tag-koryt","tag-powershell","tag-powertip"],"acf":[],"blog_post_summary":"<p>PowerShell has a concept called Streams, which are the different places data can go (output, error, verbose, etc). You usually don&#8217;t have to worry too much about these streams if you&#8217;re just writing simple scripts, but it helps a ton to know: All streams are separate even if they all appear to be coming to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/7300"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=86406"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86406\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=86406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=86406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=86406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}