Export csv spits out length only

后端 未结 3 2043
既然无缘
既然无缘 2020-12-21 14:40

I can only get the length when exporting this to csv, how should it be done properly.

$redo = Import-CSV c:\\temp\\testimport.txt | Group-Object email |
fore         


        
3条回答
  •  攒了一身酷
    2020-12-21 15:12

    Export-Csv expects an object (or a list of objects) with properties, whereas your command pipeline produces an array of strings. If you feed this array into Export-Csv the cmdlet takes the properties of each given item (which is only Length for strings) and writes those properties to the output file.

    You need to build a list of objects with the desired properties instead, e.g.:

    Import-CSV c:\temp\testimport.txt `
      | Group-Object email `
      | select @{n="Name";e={$_.Name}},@{n="Group";e={($_.Group | %{$_.group}) -join ', '}} `
      | Export-CSV c:\temp\test.csv -NoTypeInformation
    

提交回复
热议问题