powershellwrapper
powershellwrapper copied to clipboard
New-ITGlueFlexibleAssets | Convert to UTF-8 | Powershell - JSON
I need to convert my values to UTF-8
I have a Script powershell for create a new asset and when i create/send a new Flexible assets with :
New-ITGlueFlexibleAssets -data $ArrayAssets[$d]
$ArrayAssets[$d] contains this value :
{
"type": "flexible-assets",
"attributes": {
"organization-id": "0251672384978801",
"name": null,
"Traits": {
"Firstname": "éàüä",
"SID": "S-1-5-21-4248064630-212481010-4196555896-1113",
"Displayname": "éàüä",
"Description": "",
"Lastname": "",
"Useractive": "True",
"Userlogonname": "éàüä@TRY.LOCAL",
"Email": ""
},
"flexible-asset-type-id": "824162357073916"
}
}
Special characters like : éàüä don't work
My asset is created but with that "?"

i think this is a problem with Json conversion but i don't know how to convert.
If someone can help me ?
Thanks You :)
There are two parts to this problem (as far as I know). The first is the encoding of the file and the second is the encoding of PowerShell. From what I have seen, files created with Sublime Text 3 have the correct encoding but files created in PowerShell ISE or Visual Studio Code do not:

If I were to create the file in ISE and open it in Sublime, the garbage text would be seen in Sublime. VS Code seems to show the correct encoding regardless and still mess the text up in IT Glue.
The second part of the problem lays within PowerShell. If no charset is specified, Invoke-RestMethod reverts to ISO-8859-1 and specifying the charset in the header did solve the problem for some time. I can only assume IT Glue did a change on their side because this does no longer work (last I tested). You can also manually encode the body before supplying it to Invoke-RestMethod like this: [System.Text.Encoding]::UTF8.GetBytes($body). See issue #12.
My conclusion to this problem is to either use another application (for example Sublime Text 3) or modify the module to UTF8 encode the body before it is being sent to IT Glue. I have not tested this problem in PowerShell Core so it might be worth giving it a try. Please share if find another solution to this problem.
I think this issue should be closed as a duplicate of #12.