{"id":7351,"date":"2007-08-29T00:40:41","date_gmt":"2007-08-29T00:40:41","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/08\/29\/emitting-objects-verses-outputting-text-to-the-screen\/"},"modified":"2019-02-18T13:16:35","modified_gmt":"2019-02-18T20:16:35","slug":"emitting-objects-verses-outputting-text-to-the-screen","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/emitting-objects-verses-outputting-text-to-the-screen\/","title":{"rendered":"Emitting Objects verses Outputting Text to the Screen"},"content":{"rendered":"<p>Let&#8217;s face it, PowerShell does a bunch of magic for you.  If we&#8217;ve done our job right, this magic is exactly what you want 99 out of a 100 times.  That said, if you are a power user, then at some point you&#8217;ll encounter that 100<sup>th<\/sup> case and you&#8217;ll need to understand the magic so you can get PowerShell to do exactly what you want.  The good news is that our &#8220;magic&#8221; is pretty thoughtful and you can always get exactly what you want (usually with very little effort).\n<\/p>\n<p>The biggest source of magic is the formatting and outputting.  You write a function which just emits an object and wham \u2013 you get a reasonable view of that object.  If you want something different, you can easily control that with the formatting commands.  Things gets a little trickier if and when you need to understand the difference between formatting and outputting.\n<\/p>\n<p>Our formatting commands emit FORMAT OBJECTS which then USUALLY get auto-routed to an OUT-XXX command.  You can write functions where this does not happen and you can get surprised if you aren&#8217;t aware of what is going on.  James O&#8217;Neill has a great blog entry on this very issue here:  <a href=\"http:\/\/blogs.technet.com\/jamesone\/archive\/2007\/08\/28\/powershell-again-pipes-and-this-is-not-an-output.aspx\">PowerShell Again.  Pipes, and &#8220;This is not an output&#8221;<\/a> .   James wrote a very clever function which displays processes and allows you to choose one.   It came upon this issue.   All it takes is a well placed &#8221; | Out-Host&#8221; to fix the problem (I told you you&#8217;d be able to get exactly what you want with very little effort).\n<\/p>\n<p>Enjoy!\n<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows Management Partner Architect<br \/>Visit the Windows PowerShell Team blog at:    <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:  <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a>\n\t<\/p>\n<p>\n\u00a0<\/p>\n<p>Random Note:  I&#8217;ve been trying to keep up with the wonderful advances being made in the world of material science and nanotubes in particular.  I was reading Dr Zelia Zanolli&#8217;s blog about her work on a project attempting to functionalize nanotubes.  She posted a nanotube play on the painting &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/The_Treachery_Of_Images\">The Treachery of Images<\/a>&#8221;  which is a painting of a Pipe with the words &#8220;Ceci n&#8217;est pas une pipe&#8221; (this is not a pipe) <a href=\"http:\/\/nano2hybrids.net\/view_post.php?postid=91\">HERE<\/a> .  James&#8217;s blog has a cartoon spoof of the same painting.  Talk about <a href=\"http:\/\/en.wikipedia.org\/wiki\/Synchronicity\">Synchronicity<\/a>.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s face it, PowerShell does a bunch of magic for you. If we&#8217;ve done our job right, this magic is exactly what you want 99 out of a 100 times. That said, if you are a power user, then at some point you&#8217;ll encounter that 100th case and you&#8217;ll need to understand the magic so [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Let&#8217;s face it, PowerShell does a bunch of magic for you. If we&#8217;ve done our job right, this magic is exactly what you want 99 out of a 100 times. That said, if you are a power user, then at some point you&#8217;ll encounter that 100th case and you&#8217;ll need to understand the magic so [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=7351"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7351\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=7351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=7351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=7351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}