Powershell Format-Table to CSV
Asked Answered
T

2

16

I have the following line in Powershell to output an array of data. The problem I am having is that Name,Title,Department do not go into columns. Instead I get a single column with each row in a single cell with tabs between.

$outList | Format-Table Name,Title,Department -auto >c:\Scripts\test2.csv

How can I output into columns?

Tolan answered 2/5, 2014 at 18:1 Comment(0)
A
27

You should be using the Export-Csv cmdlet instead.

$outList | Export-Csv -path c:\scripts\test.csv -NoTypeInformation

If you need only selected fields, pipe it into a Select-Object cmdlet first.

$outList | Select-Object -Property Name, Title, Department | Export-Csv -path c:\scripts\test.csv -NoTypeInformation
Artiodactyl answered 2/5, 2014 at 18:14 Comment(0)
H
2

We can also use ConvertTo-Csv with select. Example:

$grades | Select Name,Count | ConvertTo-Csv
Holytide answered 13/2 at 22:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.