Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, September 29, 2016 6:16 PM
How can I get rid of the header record and remove the double quotes around data values.
This is what $data looks like currently after Export-Csv.
"9/28/2016 12:00:00 AM","16:10:00","0","0","0","0","0","0","0","1.2"
$data | Export-Csv "$exportpath\fname.csv" -NoType -Encoding Unicode -Append
I want
9/28/2016 12:00:00 AM,16:10:00,0,0,0,0,0,0,0,1.2
Thanks.
All replies (8)
Friday, September 30, 2016 5:55 AM ✅Answered | 2 votes
No need for extra files or for extra variables and no fancy replace elements. Just remove the header and the quotes and output.
One line:
$data |
ConvertTo-Csv -NoTypeInformation |
Select -Skip 1 |
ForEach-Object { $_ -replace '"' } |
Out-File "$exportpath\$fname.csv" -Encoding Unicode
\(ツ)_/
Thursday, September 29, 2016 7:15 PM
Thursday, September 29, 2016 7:22 PM
How about removing the header record?
Thanks.
Thursday, September 29, 2016 7:34 PM
Might not be the best way
Before Out-File Cmdlet
Select -Skip 1 | Out-file
Friday, September 30, 2016 1:04 AM
I need to stay with the Export-Csv as I'm load a DataTable from a SQL query to output
information.
$data = New-Object System.Data.DataTable
$reader = $sql.ExecuteReader()
$data.Load($reader)
This is how the data looks after doing the export-csv
$data | Export-Csv "$exportpath\fname.csv" -NoType -Encoding Unicode -Append
"9/28/2016 12:00:00 AM","16:10:00","0","0","0","0","0","0","0","1.2"
I want
9/28/2016 12:00:00 AM,16:10:00,0,0,0,0,0,0,0,1.2
With no headers.
Thanks.
Friday, September 30, 2016 4:36 AM
Hi,
I need to stay with the Export-Csv as I'm load a DataTable from a SQL query to output
information.
$data = New-Object System.Data.DataTable$reader = $sql.ExecuteReader()
$data.Load($reader)
This is how the data looks after doing the export-csv
$data | Export-Csv "$exportpath\fname.csv" -NoType -Encoding Unicode -Append
"9/28/2016 12:00:00 AM","16:10:00","0","0","0","0","0","0","0","1.2"
I want
9/28/2016 12:00:00 AM,16:10:00,0,0,0,0,0,0,0,1.2With no headers.
Thanks.
Please refer to my sample, I suppose it should works for you:
Get-WmiObject Win32_OperatingSystem |Select-Object CSName,Caption,Version,OSArchitecture |ConvertTo-Csv -OutVariable OutData -NoTypeInformation
$OutData[1..($OutData.count – 1)] | ForEach-Object {$_ -replace """", “”}|foreach {Add-Content -Value $_ -Path "c:\789.csv"}
For your issue, please replace like this:
$data |ConvertTo-Csv -OutVariable OutData -NoTypeInformation
$OutData[1..($OutData.count – 1)] | ForEach-Object {$_ -replace """", “”}|foreach {Add-Content -Value $_ -Path "c:\789.csv"}
Best regards,
Andy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Friday, September 30, 2016 6:14 AM
exactly what I was looking for jrv ... Many Thanks!!!!!!!!!!!!!
Thanks to all that replied...
Friday, September 30, 2016 6:19 AM
All were close but missed the simple answer.
It is like a game. What can you stick together to make the input into the output.
God luck.
\(ツ)_/