Export-CSV ignores Delimiter when using -Encoding

Hi all,

my name is Thomas and I am pretty new to powershell. I already searched the internet, but I can’t find an answer, so I hope you can provide some tips.

I am reading out some XML files with my powershell script and writing the content into an array.

At the end, when I just type in the array name into the console, I see the correct output in 3 tables. When I try to export it to csv using this code:

$DataArray | Export-Csv C:\Users\xxx\Desktop\report.csv -Delimiter ";" -NoTypeInformation

The created report.csv file shows the correct content in 3 tables, which is perfect. But there is one issue. The content contains a german umlaut like Ä,Ö,Ü and these are not displayed.

No problem, when I use -Encoding unicode, everything looks fine.

But now it gets weird:
As soon as I add the encoding

$DataArray | Export-Csv C:\Users\xxx\Desktop\report.csv -Delimiter ";" -Encoding Unicode -NoTypeInformation

Export-Csv seems to ignore the Delimiter, as from now on I will only have one table in the report.csv.

Can somebody please explain to me why this is happening? I need the data in 3 tables like I builded the array, but I also need it with the proper encoding.

Thank you very much for reading!

Best regards,
Thomas

Can you give an example of the tables? Wouldn’t a csv only have one table with one set of headers?

I assume you meant columns when you say tables, right? … did you try another encoding? … like UTF8? Did you try another delimiter? Could you post some sample lines of your data from “before” and from “after” the export? Please format these sample data as code as well.

Hi,

thanks for the fast reply.

Benutzer	Termin	                        ?nderungsdatum
c12345	        2019-02-26T16:00:00+01:00	Samstag, 2. M?rz 2019 12:41:28
c12345	        2019-02-23T10:10:00+01:00	Samstag, 2. M?rz 2019 23:52:37
c12345	        2019-02-27T10:00:00+01:00	Samstag, 2. M?rz 2019 12:46:08
c12345	        2019-02-23T09:30:00+01:00	Samstag, 2. M?rz 2019 11:47:48
c12345	        2019-03-02T09:30:00+01:00	Samstag, 2. M?rz 2019 10:10:33
c12345	        2019-02-22T15:30:00+01:00	Samstag, 2. M?rz 2019 11:51:53
c12345	        2019-02-23T11:30:00+01:00	Samstag, 2. M?rz 2019 11:55:58
c12345	        2019-02-25T07:30:00+01:00	Samstag, 2. M?rz 2019 12:01:03
c12345	        2019-02-26T10:00:00+01:00	Samstag, 2. M?rz 2019 12:21:03

Note: I replaced the correct userID (Benutzer) with the placeholder c12345. This is what the report looks like without -Encoding.

Thanks,
Thomas

Hi Olaf,

sorry, did not see your reply directly. Yes, I mean colums, sorry.

When I use the Delimiter “,” the report will only have onw column. With “;” as Delimiter it has 3 columns like it should. I did not test any other Delimiter.

I am not quite sure what you mean with “before and after the export”. The sample above shows the content of report.csv with using Delimiter “;” and without using -Encoding Unicode.

The content of $DataArray in the console is:

Benutzer Termin                    Änderungsdatum                
-------- ------                    --------------                
c12345   2019-02-26T16:00:00+01:00 Samstag, 2. März 2019 12:41:28
c12345   2019-02-23T10:10:00+01:00 Samstag, 2. März 2019 23:52:37
c12345   2019-02-27T10:00:00+01:00 Samstag, 2. März 2019 12:46:08
c12345   2019-02-23T09:30:00+01:00 Samstag, 2. März 2019 11:47:48
c12345   2019-03-02T09:30:00+01:00 Samstag, 2. März 2019 10:10:33
c12345   2019-02-22T15:30:00+01:00 Samstag, 2. März 2019 11:51:53
c12345   2019-02-23T11:30:00+01:00 Samstag, 2. März 2019 11:55:58
c12345   2019-02-25T07:30:00+01:00 Samstag, 2. März 2019 12:01:03
c12345   2019-02-26T10:00:00+01:00 Samstag, 2. März 2019 12:21:03

Thanks,
Thomas

Hmmm … that’s gonna be hard to debug without your environment. … we Germans with our Umlaute … :wink: How do you invoke the exported data? With Excel or do you import them back to Powershell? Try do use another delimiter. Just omit the paramter. The comma is the default.

It seems ok to me. What version of powershell do you have? Don’t forget to specify -delimiter “;” when running import-csv later.

"Benutzer";"Termin";"Änderungsdatum"
"c12345";"2019-02-26T16:00:00+01:00";"Samstag, 2. März 2019 12:41:28"
"c12345";"2019-02-23T10:10:00+01:00";"Samstag, 2. März 2019 23:52:37"
"c12345";"2019-02-27T10:00:00+01:00";"Samstag, 2. März 2019 12:46:08"
"c12345";"2019-02-23T09:30:00+01:00";"Samstag, 2. März 2019 11:47:48"
"c12345";"2019-03-02T09:30:00+01:00";"Samstag, 2. März 2019 10:10:33"
"c12345";"2019-02-22T15:30:00+01:00";"Samstag, 2. März 2019 11:51:53"
"c12345";"2019-02-23T11:30:00+01:00";"Samstag, 2. März 2019 11:55:58"
"c12345";"2019-02-25T07:30:00+01:00";"Samstag, 2. März 2019 12:01:03"
"c12345";"2019-02-26T10:00:00+01:00";"Samstag, 2. März 2019 12:21:03"

Hi Olaf,

I only tested other delimiters and ignored the part where you asked for testing different encodings.

UTF8 works like a charme, thanks!

Best regards,
Thomas