Reputation: 229
I am trying to export an ArrayList object to a CSV file. The object is a list of 3 element arrays.
I have been trying something like the following however I just get information about the object (number of elements, length, etc).
$CsvArrayList | Export-Csv "./Output.csv"
Is it possible to output the values contained in an array list into csv format? Ideally one line per array and one element per cell.
Upvotes: 3
Views: 13504
Reputation: 5452
You could create the CSV manually using -join
, however this may be slow if there are lots of arrays:
$CSVArrayList = new-Object System.Collections.ArrayList
[void]$CSVArrayList.Add(@('1','2','3'))
[void]$CSVArrayList.Add(@('4','5','6'))
Set-Content "./Output.csv" -Value $null
Foreach ($arr in $CSVArrayList) {
$arr -join ',' | Add-Content "./Output.csv"
}
Upvotes: 1