PS – External Utilities – german console with umlauts

Hi all,

i am using a german console with german words. Many of you know that we use “very special characters” also called umlauts: “ÄÜÖ”.

The interesting part is – if you try to use external tools as the following and they normally would return any values with umlauts this will not work out from Powershell; Let´s say for this example you created a shared directory named ‘ÄÜÖ’:

net.exe VIEW \\localhost\ /all

Here you would get something like this by using it in Powershell:


Freigabename  Typ     Verwendet als  Kommentar         

-------------------------------------------------------------------------------
ADMIN$        Platte                 Remoteverwaltung
Bilder        Platte
C$            Platte                 Standardfreigabe
IPC$          IPC                    Remote-IPC
print$        Platte                 Druckertreiber
Users         Platte
Ž™š           Platte
Der Befehl wurde erfolgreich ausgefhrt.

This error is caused by not matching encodings. Therefore these have to be set previously for the console itself. But here comes again another tricky part. Till now – you would get an error by setting the consoles encoding without having used the cmd.exe out of powershell before, because the handle to the console has to be created previously. Therefore the way to get this to work would be like this:

cmd /c ''
if ([Console]::OutputEncoding.CodePage -ne 852 )
{
    [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(852)
}
net.exe VIEW \\localhost\ /all

#getting only the specific line
net.exe VIEW \\localhost\ /all | Select-String 'Ö'
net.exe VIEW \\localhost\ /all | Where-Object { $_ -like '*Ö*' }

With following result:

Freigabename  Typ     Verwendet als  Kommentar         

-------------------------------------------------------------------------------
ADMIN$        Platte                 Remoteverwaltung  
Bilder        Platte                                   
C$            Platte                 Standardfreigabe  
IPC$          IPC                    Remote-IPC        
print$        Platte                 Druckertreiber    
Users         Platte                                   
ÄÖÜ           Platte                                   
Der Befehl wurde erfolgreich ausgeführt.

I am pretty sure that german readers may need this information some time.

Best regards,
David

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s