PSCredential containing German umlauts in New-WebServiceProxy PSCredential containing German umlauts in New-WebServiceProxy powershell powershell

PSCredential containing German umlauts in New-WebServiceProxy


Interesting. Your workaround led me to this more general workaround, which does not depend on saving incorrectly encoded script files. Instead, it incorrectly encodes the password string only

Let me know if this works.

$pw = 'abÜ312!'# incorrectly encode the UTF8-bytes as ANSI (this yields abÃœ312!)$dummy = [Text.Encoding]::Default.GetString([Text.Encoding]::UTF8.GetBytes($pw))$secp = ConvertTo-SecureString $dummy -AsPlainText -Force

I assume this will not work for any characters, but I don't know enough about encodings to say for sure.


The linked answer from mklement0 led me to the solution:

The script was written and saved using PowerShell ISE. I just realized that ISE was saving the file using the UTF-8 with BOM encoding. If I change the encoding to UTF-8 everything works.

Here is a short script to change the encoding of a file to UTF-8:

$scriptPath = "c:/path/to/script.ps1"$content = Get-Content -Raw $scriptPath[System.IO.File]::WriteAllLines($scriptPath, $content, (New-Object System.Text.UTF8Encoding))