简体   繁体   中英

Export-Csv and Array objects

I have a CSV that I want to process in an array object and export as another CSV. However when I do that, instead of copying the values of the array, it copies the attribute of the object.

"Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized","Count"
"52","52","1","System.Object[]","False","True","False","52"

How can resolve this?

EDIT :

The code that caused this:

Export-Csv $data test.csv

Where $data is the array that stores the output of the import-csv.

Apparently -InputObject became a positional parameter in PowerShell v6, otherwise the code you posted should've thrown an error

Export-Csv: Cannot bind parameter 'Delimiter'. Cannot convert value "test.csv" to type "System.Char". Error: "String must be exactly one character long."

Anyway, the code you posted is effectifly running

Export-Csv -InputObject $data -Path test.csv

However, the parameter -InputObject takes a single PSObject argument, not an array of PSObjects. If you pass it an array, the CSV output is created from that array object, not from the elements of the array.

Pipe the array to Export-Csv to have the output created from the array elements:

$data | Export-Csv -Path test.csv -NoType

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM