Transfer German Umlaute with Invoke-RestMethod

Right now, I am working on a PowerShell script to Sync Tasks from Notion to my Microsoft Todo and back. In that case, I am using “Invoke-RestMethod” many times. And as I am in Austria and write some ToDos in German, I have to use “Umlaute” like “ä”,”ü”,”ö “.

This can be challenging, and I have faced that problem multiple over the past years, but I always started from scratch to figure out the solution. So I decided to write this down for you and for me.

The solution is straightforward, but let me explain a little.

We use the following Script to create a Microsoft ToDo Task

$title="This is a Test"

$JsonBody = @"
{
    "title":"$title"
}
"@

Invoke-RestMethod -Method POST -Headers $headers -Uri $URLCreateTask -Body $JsonBody

To get more details on creating an MS ToDo Task with PowerShell and GRAPH API, see my BlogPost here: Create Microsoft ToDo Task with PowerShell and Microsoft GRAPH API – TechGuy

The Result is the following

So far, so good, but now let’s try with “Umlaute” and use that Script

$title="Das ist eine Übung"

$JsonBody = @"
{
    "title":"$title"
}
"@

Invoke-RestMethod -Method POST -Headers $headers -Uri $URLCreateTask -Body $JsonBody

And here you see the problem. There is a strange Sign instead of “Ü.”

There is an easy solution, add the following to the Invoke-RestMethod “-ContentType “application/json; charset=utf-8”” and run the Script.


$title="Das ist eine Übung"

$JsonBody = @"
{
    "title":"$title"
}
"@

Invoke-RestMethod -Method POST -Headers $headers -Uri $URLCreateTask -Body $JsonBody -ContentType "application/json; charset=utf-8"

The Result now looks much better.

So, remember to add

-ContentType "application/json; charset=utf-8"

to your Invoke-RestMethod to ensure that the German Umlaute are sent correctly.

Michael Seidl, aka Techguy
au2mate, everything

Leave a Comment

Your email address will not be published.

*

%d bloggers like this: