Powershell invoke-webrequest with xml soap envelope body containing £ char errors


I’m trying to use Powershells Invoke-Webrequest to send a soap envelope to a password protected web service. The password contains the ‘£’ char, which is causing the following error:

This is the script (sensitive information removed):

It doesnt seem to matter what type/encoding I force the $SOAP to be, Invoke-Webrequest insists on interpreting the ‘£’ as a ‘�’.

Any ideas?


It certainly looks like an encoding issue, so here’s a few things you can try.

Make sure your file is saved as UTF-8. Use notepad.exe to open it and select Save As. At the bottom there’s an “Encoding” dropdown. It should say UTF-8. If not, change it and overwrite the file.

In Powershell print out the file using the type or get-content command. The pound sign should be displayed as a pound sign, not like a question mark.
Saving it using notepad (or another editor) in the correct encoding should fix this.

Another thing that might work is storing the SOAP message in a separate file encoded as UTF-8 (or Unicode).
Then get the content of the file using Get-Content using the -Encoding parameter and the type you saved it with.
Again, this is to make sure the pound sign isn’t mangled before it’s used in the service call.

If that doesn’t work, maybe you can get the password using Read-Host and combine the SOAP message using that.

Last, you can always change the password so it has no characters in the unicode range. You can still use a bunch of special characters as long as they are in the lower ASCII range. E.g. %=+-)ç!”# etc.
But that’s a last resort I guess.


Powershell invoke-webrequest with xml soap envelope body containing £ char errors by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply