{"id":8311,"date":"2007-03-07T00:24:55","date_gmt":"2007-03-07T00:24:55","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/03\/07\/why-cant-i-pipe-format-table-to-export-csv-and-get-something-useful\/"},"modified":"2019-02-18T13:16:49","modified_gmt":"2019-02-18T20:16:49","slug":"why-cant-i-pipe-format-table-to-export-csv-and-get-something-useful","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/why-cant-i-pipe-format-table-to-export-csv-and-get-something-useful\/","title":{"rendered":"Why Can&#8217;t I Pipe Format-Table to Export-Csv (and get something useful)?"},"content":{"rendered":"<p>Ken&#8217;s PowerShell blog has an entry <a href=\"http:\/\/kentaylor.spaces.live.com\/Blog\/cns!7E6EBC6F4550C78A!132.entry\">Remote Services and PowerShell<\/a> where he wrote a function to get services from a remote machine using WMI.  He formatted the data using FT (format-table) and then went on to export the data to CSV.  He pointed out that the following would NOT work\n<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"color:#1f497d;font-family:Courier New;font-size:9pt\"><em>rget-service remotemachinename netlogon | ft -autosize name,startmode,state,status,startname | export-csv services.csv\n<\/em><\/span><\/p>\n<p>Instead you should use:\n<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"color:#1f497d;font-family:Courier New;font-size:9pt\"><em>rget-service remotemachinename netlogon | Select-Object name,startmode,state,status,startname | export-csv services.csv\n<\/em><\/span><\/p>\n<p>Let&#8217;s take a minute to explore why the first command does not work.  Let&#8217;s replace the Export-CSV with a Get-Member and see what we get:\n<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-family:Courier New;font-size:9pt\"><span style=\"color:#1f497d\">Ps&gt; rget-service remotemachinename netlogon | ft -autosize name,startmode,state,status,startname | Get-Member \u2013MemberType Property<\/p>\n<p>   TypeName: <\/span><span style=\"color:red\"><strong>Microsoft.PowerShell.Commands.Internal.Format.FormatStartData<\/strong><\/span><span style=\"color:#1f497d\"><strong><br \/><\/strong><br \/>Name                                    MemberType Definition<br \/>&#8212;-                                    &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>autosizeInfo                            Property   Microsoft.PowerShell&#8230;.<br \/>ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   System.String ClassId&#8230;<br \/>groupingEntry                           Property   Microsoft.PowerShell&#8230;.<br \/>pageFooterEntry                         Property   Microsoft.PowerShell&#8230;.<br \/>pageHeaderEntry                         Property   Microsoft.PowerShell&#8230;.<br \/>shapeInfo                               Property   Microsoft.PowerShell&#8230;.<\/p>\n<p>   TypeName: <\/span><span style=\"color:red\"><strong>Microsoft.PowerShell.Commands.Internal.Format.GroupStartData<\/strong><\/span><span style=\"color:#1f497d\"><strong><br \/><\/strong><br \/>Name                                    MemberType Definition<br \/>&#8212;-                                    &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   System.String ClassId&#8230;<br \/>groupingEntry                           Property   Microsoft.PowerShell&#8230;.Pitn<br \/>shapeInfo                               Property   Microsoft.PowerShell&#8230;.<\/p>\n<p>   TypeName: <\/span><span style=\"color:red\"><strong>Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData<\/strong><br \/><\/span><span style=\"color:#1f497d\"><br \/>Name                                    MemberType Definition<br \/>&#8212;-                                    &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   System.String ClassId&#8230;<br \/>formatEntryInfo                         Property   Microsoft.PowerShell&#8230;.<br \/>outOfBand                               Property   System.Boolean outOfB&#8230;<br \/>writeErrorStream                        Property   System.Boolean writeE&#8230;<\/p>\n<p>   TypeName: <\/span><span style=\"color:red\"><strong>Microsoft.PowerShell.Commands.Internal.Format.GroupEndData<\/strong><\/span><span style=\"color:#1f497d\"><\/p>\n<p>Name                                    MemberType Definition<br \/>&#8212;-                                    &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   System.String ClassId&#8230;<br \/>groupingEntry                           Property   Microsoft.PowerShell&#8230;.<\/p>\n<p>   TypeName: <\/span><span style=\"color:red\"><strong>Microsoft.PowerShell.Commands.Internal.Format.FormatEndData<\/strong><\/span><span style=\"color:#1f497d\"><\/p>\n<p>Name                                    MemberType Definition<br \/>&#8212;-                                    &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>ClassId2e4f51ef21dd47e99d3c952918aff9cd Property   System.String ClassId&#8230;<br \/>groupingEntry                           Property   Microsoft.PowerShell&#8230;.<\/p>\n<p><em>\n\t\t\t\t<\/em><\/span><\/span><\/p>\n<p>What you are seeing is that Format-Table transforms the objects into a stream of formatting directives.  These are then consumed by one of the OUT- Commands (Out-Host, Out-File, Out-String, Out-Printer).   This is why you can&#8217;t pipe format-table to export-csv.\n<\/p>\n<p>Enjoy!\n<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC 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>Ken&#8217;s PowerShell blog has an entry Remote Services and PowerShell where he wrote a function to get services from a remote machine using WMI. He formatted the data using FT (format-table) and then went on to export the data to CSV. He pointed out that the following would NOT work rget-service remotemachinename netlogon | ft [&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":[10],"class_list":["post-8311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-faq"],"acf":[],"blog_post_summary":"<p>Ken&#8217;s PowerShell blog has an entry Remote Services and PowerShell where he wrote a function to get services from a remote machine using WMI. He formatted the data using FT (format-table) and then went on to export the data to CSV. He pointed out that the following would NOT work rget-service remotemachinename netlogon | ft [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8311","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=8311"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8311\/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=8311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}