Microsoft Graph, JSON und Umlaute

Ergebnisse aus Anfragen an Microsoft Graph liefert es meist im JSON-Format zurück. In den Ergebnissen werden Umlaute, Sonderzeichen oder andere Zeichen oft nicht korrekt dargestellt.

Für die Lösung gibt es zwei Optionen. In einigen Fällen ist die erste Option ausreichend, in anderen Fällen benötigt ihr beide Optionen.

1. Gebt den Zeichensatz im ContentType mit.

PowerShell
Invoke-RestMethod -Uri $MSGraphUrl -Headers $AuthHeader -Method Get -ContentType 'application/json; charset=utf-8'

Es können weiterhin Umlaute falsch dargestellt werden.

2. Enkodiert das Ergebnis aus MSGraph mit dem korrekten Zeichensatz.

PowerShell
$MSGraphResults = Invoke-RestMethod -Uri $MSGraphUrl -Headers $AuthHeader -Method Get -ContentType  'application/json; charset=utf-8'  
$EncodedResults = [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding(28591).GetBytes($MSGraphResults))
Share this post:

About the Author

Tobias Asböck

Tobias Asböck

Tobias is a Senior System Engineer with more than 10 years of professional experience with Microsoft 365 products such as SharePoint Online, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities. If you have additional questions, please contact me via LinkedIn or support@topedia.com.

No comments yet