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
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