German umlauts are in force. Iterating over directory doesn't work

I am trying to iterate over a folder. It works for the entire folder, but not for directories with umauts. After the script shows what the problem is:

$source= @("D:\XLS_Abrufe-ÜNB")
foreach ($element in $source) {
    $element
    cmd /c dir /ad /b /s $element |foreach{
        $_
    }
}

      

Output:

D:\XLS_Abrufe-ÜNB

D:\XLS_Abrufe-šNB\2015
D:\XLS_Abrufe-šNB\2016
D:\XLS_Abrufe-šNB\2017

      

If I try to work with those names it won't find the folder. Any ideas how to get this working with umlauts?

+3


source to share


2 answers


Are you trying to get all directories in D:\XLS_Abrufe-ÜNB

? In my experience cmd doesn't handle Unicode very well.



$source= @("D:\XLS_Abrufe-ÜNB")
Get-ChildItem $source -force |
  Where-Object { $_.IsPSContainer } |
  $_

      

+2


source


You are breaking an external command, in this case the prompt cmd

that the console host uses. On Windows, the console host still uses code pages, so while PowerShell understands the character perfectly, the console host most likely doesn't understand the encoding.



If you are using native PowerShell entirely ( as in TheIncorrigible1's answer ) it should work fine.

+1


source







All Articles