Keep merging of several CSV umlauts

Hello everybody,
What else do I have to add in my code so that the umlauts are retained?

$result = "C:\Users\Jens\Desktop\Schichtenauswertung_EVA\CSVExport\Umwandeln_in_Excel\Schichtenauswertung.csv"
$csvs = get-childItem "C:\Users\Jens\Desktop\Schichtenauswertung_EVA\CSVExport\Schichtenuebesicht\*.csv"
#read and write CSV header
[System.IO.File]::WriteAllLines($result,[System.IO.File]::ReadAllLines($csvs[0])[0])
#read and append file contents minus header
foreach ($csv in $csvs)  {
    $lines = [System.IO.File]::ReadAllLines($csv)
    [System.IO.File]::AppendAllText($result, ($lines[1..$lines.Length] | Out-String))

@Jens Welcome to PowerShell.org forums.

What are umlauts ?. Can you tell a little more on what you are trying to do and post the error if you are getting any.

PS: I’ve formatted the code for you, please use the code symbol on the tool bar while posting the code.

Guide to Posting Code - Redux - PowerShell Help - PowerShell Forums

Jens,

is there a special reason why you’re not using the pure PowerShell way to read and write (CSV) files? … or files in general? Usually it’s easier to maintain German umlauts this way. Import-Csv and Export-Csv have the parameter -Encoding. Provided the value UTF8 usually solves problems with umlauts.

And just to mention it at least once … of course Get-Content, Set-Content, Add-Content and Out-File offer the same parameter -Encoding.

@kvprasoon

:wink:

1 Like