I want to read a CSV file and output a CSV file with only one (1) field. I have tried to create a concise example.
PS C:srcpowershell> Get-Content ..csv
field1,field2,field3
1,2,3
4,55,6
7,888,9
PS C:srcpowershell> Import-Csv -Path ..csv | `
>> ForEach-Object {
>> $_.field2 `
>> } | `
>> Export-Csv -Path .x.csv -NoTypeInformation
>>
The problem is that the Length of field2 is written to the exported CSV file. I want the field header to be "field2" and the values to be the value from the original CSV file. Also, I only want quotes where they are required; not everywhere.
I have read Export-CSV exports length but not name and Export to CSV only returning string length. But these do not seem to address producing an actual CSV file with a header and one field value.
PS C:srcpowershell> get-content .x.csv
"Length"
"1"
"2"
"3"
See Question&Answers more detail:os