powershell convert array of hastables into csv


Have done googling but have not found suitable answer

I have

I get only last line in cab. I want all the lines


It’s truth that Export-Csv won’t append (< v3), but I do not think ConvertTo-Csv will solve the problem… In the end you will get file with headers repeated for every object in your array. I would suggest one of two things:

  • move Export-Csv outside foreach {} (need to put it in subexpression though, because it won’t be possible to pipe it by default)
  • use Foreach-Object instead and get same results

I would also suggest to use New-Object PSObject -Property parameter instead of adding members later: because you use hashtable as a base you are half way there, see attached code samples:


powershell convert array of hastables into csv by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply