powershellwrapper icon indicating copy to clipboard operation
powershellwrapper copied to clipboard

New-ITGlueFlexibleAssets | Convert to UTF-8 | Powershell - JSON

Open VincentRime opened this issue 5 years ago • 1 comments

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 "?" 2020-01-14_09-01-46

i think this is a problem with Json conversion but i don't know how to convert.

If someone can help me ?

Thanks You :)

VincentRime avatar Jan 14 '20 08:01 VincentRime

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:

encoding

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.

ecspresso avatar Jan 15 '20 08:01 ecspresso

I think this issue should be closed as a duplicate of #12.

davidhaymond avatar Dec 05 '22 19:12 davidhaymond