SOLVED

Accented characters lost when calling Microsoft Graph from Powershell script

%3CLINGO-SUB%20id%3D%22lingo-sub-1900887%22%20slang%3D%22en-US%22%3EAccented%20characters%20lost%20when%20calling%20Microsoft%20Graph%20from%20Powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1900887%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wrote%20a%20script%20to%20create%2C%20update%20or%20delete%20contacts%20in%20one%20of%20my%20Exchange%20contacts%20folder%20by%20using%20Invoke-RestMethod%20cmdlet%20to%20call%20Microsoft%20Graph%20API.%3C%2FP%3E%3CP%3EThe%20issue%20is%20that%20accented%20characters%20are%20replaced%20with%20the%20Unicode%20replacement%20character%20(a%20black%20diamond%20with%20a%20white%20question%20mark)%20in%20contacts%20properties%20where%20such%20accented%20characters%20should%20be%20displayed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20instance%20when%20updating%20jobTitle%20property%20with%20characters%20'%C3%A9%C3%A7%C3%A8%C3%A0'%2C%20I%20get%20four%20replacement%20characters%20as%20shown%20in%20the%20attached%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20with%20%3A%3C%2FP%3E%3CP%3E-%20PowerShell%20ISE%205.1%3C%2FP%3E%3CP%3E-%20PowerShell%207.0.3%20terminal%3C%2FP%3E%3CP%3E-%20VS%20Code%201.50.1%20with%20Powershell%20Extension%202020.6.0%3C%2FP%3E%3CP%3E-%20PowerShell%20within%20Azure%20Function%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECalling%20Microsoft%20Graph%20API%20with%20some%20other%20API%20specialized%20software%20is%20successful%20%3A%20the%20accented%20characters%20get%20displayed%20in%20the%20Exchange%20contacts%20properties.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20a%20beginner%20in%20PowerShell%20scripting%20and%20with%20all%20aspects%20of%20using%20.Net%20functionalities.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1900887%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

Hi,

 

I wrote a script to create, update or delete contacts in one of my Exchange contacts folder by using Invoke-RestMethod cmdlet to call Microsoft Graph API.

The issue is that accented characters are replaced with the Unicode replacement character (a black diamond with a white question mark) in contacts properties where such accented characters should be displayed.

 

For instance when updating jobTitle property with characters 'éçèà', I get four replacement characters as shown in the attached file.

 

I tried with :

- PowerShell ISE 5.1

- PowerShell 7.0.3 terminal

- VS Code 1.50.1 with Powershell Extension 2020.6.0

- PowerShell within Azure Function

 

Calling Microsoft Graph API with some other API specialized software is successful : the accented characters get displayed in the Exchange contacts properties.

 

I'm a beginner in PowerShell scripting and with all aspects of using .Net functionalities.

 

Thanks for your help.

2 Replies
Best Response confirmed by AlainKlein (New Contributor)
Solution

@AlainKlein 

I did not work yet with MG, but did you try the following

But I can refer you to similar case

https://powershell.org/forums/topic/character-encoding-with-invoke-restmethod/

Plus you can get more information about the encoding from here.

https://docs.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/understanding-file-encod...

 

@farismalaeb 

 

Hi,

Thanks a lot for your reply : one of the solutions provided in Topic: Character encoding with Invoke-RestMethod | PowerShell.org works for us. :)

 

Many thanks for your advice and time spent responding to us.

 

Have a nice day.

Stay safe.

 

Alain Klein