0

I am having data in the database. Using Powershell Invoke-RestMethod, I am trying to fetch the data. When I am trying to save the output to a Variable and print it, it is showing me invalid characters (not same as Original).

Below is the Data stored in the database

GCM – PLPD Resource RW

Here's my code

$output=Invoke-RestMethod -Method Post -Uri $WebServiceURL -Body $json -ContentType "Application/json"
Write-Host $output.OutputObject.SUBROOT

Below is my Output with Invalid Characters

@{SecurityGroupName=GCM – PLPD Resource RW}
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27
  • 3
    I can only guess here. But maybe `-ContentType` should be `'Application/json; charset=utf-8'`. If there is an issue with `$body`, that may need to be converted to `UTF8` and/or byte format as well. – AdminOfThings Jun 23 '20 at 13:20
  • Here's a link with some google juice: https://powershell.org/forums/topic/character-encoding-with-invoke-restmethod/ – js2010 Jun 23 '20 at 13:20
  • Also, if your code lies within a script or module file, ensure the file is encoded as UTF-8. And it might be worthwhile to check the `$OutputEncoding` preference variable in your PowerShell host console too. If you need to change it, check `[System.Text.Encoding]::GetEncodings()` for available options. For example, for UTF-8, the command would be: `$OutputEncoding = [System.Text.Encoding]::GetEncoding(65001)` – leeharvey1 Jun 24 '20 at 12:48

0 Answers0