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 ausgefhrt.
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