导出 csv 只吐出长度 [英] Export csv spits out length only
问题描述
我只能在导出到csv时得到长度,应该如何正确完成.
$redo = 导入-CSV c:\temp\testimport.txt |组对象电子邮件 |foreach { "{0} ,{1}" -f $_.Name, (($_.Group | foreach { $_.group }) -join ', ')}$重做 |导出-CSV c:\temp\test.csv -NoTypeInformation
#<块引用>
长度"46"59"110"47"149"38"69"32"62"29"49"31""27" "48" "55" "42"
Export-Csv
需要一个具有属性的对象(或对象列表),而您的命令管道产生一个字符串数组.如果您将此数组输入到 Export-Csv
中,则 cmdlet 会获取每个给定项的属性(对于字符串而言仅为 Length
)并将这些属性写入输出文件.
您需要构建具有所需属性的对象列表,例如:
Import-CSV c:\temp\testimport.txt `|组对象电子邮件`|select @{n="Name";e={$_.Name}},@{n="Group";e={($_.Group | %{$_.group}) -join ', '}}`|导出-CSV c:\temp\test.csv -NoTypeInformation
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 |
foreach { "{0} ,{1}" -f $_.Name, (($_.Group | foreach { $_.group }) -join ', ')
}
$redo | Export-CSV c:\temp\test.csv -NoTypeInformation
#
"Length" "46" "59" "110" "47" "149" "38" "69" "32" "62" "29" "49" "31" "27" "48" "55" "42"
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
这篇关于导出 csv 只吐出长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!