Export-Csv - why is PowerShell adding delimiter "" - how to avoid this

Daoust ICT
Daoust ICT used Ask the Experts™
on
Export-Csv - why is PowerShell adding delimiter ""

Export-Csv -Path $CSVFile -Encoding UTF8 –delimiter ";" -NoTypeInformation


I have a csv file with this content (before Export)

ExportedOn;Process;DateValue;LogonName;FirstName;LastName;Function;SiteCode;Departement;AppGap;AppSmile;Intranet;Desktop;LapTop;GSM;SmartPhone;VPNAccess;ResetADRights;SDTicket;RFPD
24/07/2018 05:36;Create;02/11/2019 00:00;flastnamei;firstname;lastname;Stagiaire;SI;Job Coaching Bruxelles;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;TRUE;;;


when i use the command

Export-Csv -Path $CSVFile -Encoding UTF8 –delimiter ";" -NoTypeInformation
the file is changed like this

"ExportedOn";"Process";"DateValue";"LogonName";"FirstName";"LastName";"Function";"SiteCode";"Departement";"AppGap";"AppSmile";"Intranet";"Desktop";"LapTop";"GSM";"SmartPhone";"VPNAccess";"ResetADRights";"SDTicket";"RFPD"
"24/07/2018 05:36";"Create";"02/11/2019 00:00";"flastname";"firstname";"lastname";"Stagiaire";"SI";"Job Coaching Bruxelles";"FALSE";"FALSE";"TRUE";"FALSE";"TRUE";"FALSE";"FALSE";"TRUE";;"";""

"" are added which is really annoying….

why ???
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AlexSenior Infrastructure Analyst

Commented:
Ok

Run

Export-Csv -Path $CSVFile -NoTypeInformation

Open in new window


Don't stipulate the delimiter or the encoding and see how you get on. If that doesn't work, use UNICODE and not UTF.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
It's not adding a delimiter; it's adding quotes around the fields, because it's the safest way to export. What happens otherwise if one of the fields contains the delimiter in the text?
If you are absolutely, one hundred percent, sure that the delimiter is not and will never show up in any of the fields, you canuse this as workaround to replace the Export-Csv command:
... | ConvertTo-Csv -Delimiter ';' -NoTypeInformation |
	ForEach-Object {$_.Trim('"').Replace('";"', ';')} |
	Set-Content -Path $CSVFile -Encoding UTF8

Open in new window


Edit:
To clarify that: the cmdlet is not generating (with ; as delimiter, spaces inserted for clarity)
field1  ";"  field2  ";"  field3

Open in new window

It is generating
"field1"  ;  "field2"  ;  "field3"

Open in new window

Daoust ICTIcT service Desk

Author

Commented:
tks. strange that at the beginning the file was not containing the ""
Anyway, I'm happy with this now that I understand

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial