{"id":7241,"date":"2007-09-15T10:48:56","date_gmt":"2007-09-15T10:48:56","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/09\/15\/outputting-vs-emitting-objects\/"},"modified":"2019-02-18T13:16:31","modified_gmt":"2019-02-18T20:16:31","slug":"outputting-vs-emitting-objects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/outputting-vs-emitting-objects\/","title":{"rendered":"Outputting vs. Emitting Objects"},"content":{"rendered":"<p>Sunil wrote:\n<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-family:Arial;font-size:10pt\">Hello,\n<\/span><\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-family:Arial;font-size:10pt\">Firstly i am sorry to post an unrelated question to this post. However i dont know where to post my questions. Here is my question<br \/>Say I have 2 cmdlet&#8217;s<br \/>Get-location<br \/>Get-service<br \/>When I create a test.ps1 file out of these 2 command and then run it, it will always do a <br \/>Get-service |fl \u00a0in the output<br \/>Ie. A full listing of the second command. Is there a way we can avoid this?\n<\/span><\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-family:Arial;font-size:10pt\">thanks,\n<\/span><\/p>\n<p>As a general rule, the best place to ask questions is the PowerShell Newsgroup:  Microsoft.Public.Windows.PowerShell\n<\/p>\n<p>What you are seeing with your script is that your script does not PRINT (&#8220;OUTPUT to the HOST&#8221;) the LOCATION and then the SERVICEs.  Instead it EMITS them (&#8220;WRITES to the OUTPUT STREAM&#8221;).\n<\/p>\n<p>Unless you connect things otherwise, the objects on the output stream are sent to some code that will output them to the host AS A COLLECTION.  The way that works is that the first object in the collection is used to determine how the rest of the collection will be output.  If that code finds something unanticipated in the collection, it just formats it as a list and continues.  You can prove this to yourself by doing the following:\n<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-family:Consolas\">PS&gt; gps idle;pwd;gps system<br \/>Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName<br \/>&#8212;&#8212;-  &#8212;&#8212;    &#8212;&#8211;      &#8212;&#8211; &#8212;&#8211;   &#8212;&#8212;     &#8212; &#8212;&#8212;&#8212;&#8211;<br \/>      0       0        0         28     0               0 Idle<\/p>\n<p>Drive        : C<br \/>Provider     : Microsoft.PowerShell.Core\\FileSystem<br \/>ProviderPath : C:\\ps<br \/>Path         : C:\\ps<\/p>\n<p>    664       0        0      16872    20               4 System<br \/>\n\t\t<\/span><\/p>\n<p>What you want to do is:\n<\/p>\n<p style=\"margin-left: 36pt\">Get-Location | Out-Host\n<\/p>\n<p style=\"margin-left: 36pt\">Get-Service | Out-Host\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","protected":false},"excerpt":{"rendered":"<p>Sunil wrote: Hello, Firstly i am sorry to post an unrelated question to this post. However i dont know where to post my questions. Here is my questionSay I have 2 cmdlet&#8217;sGet-locationGet-serviceWhen I create a test.ps1 file out of these 2 command and then run it, it will always do a Get-service |fl \u00a0in the [&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-7241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Sunil wrote: Hello, Firstly i am sorry to post an unrelated question to this post. However i dont know where to post my questions. Here is my questionSay I have 2 cmdlet&#8217;sGet-locationGet-serviceWhen I create a test.ps1 file out of these 2 command and then run it, it will always do a Get-service |fl \u00a0in the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7241","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=7241"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7241\/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=7241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=7241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=7241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}