{"id":10813,"date":"2020-09-27T21:23:16","date_gmt":"2020-09-27T20:23:16","guid":{"rendered":"https:\/\/myworldofit.net\/?p=10813"},"modified":"2020-09-27T21:24:50","modified_gmt":"2020-09-27T20:24:50","slug":"prtg-rest-api-powershell-and-utf8","status":"publish","type":"post","link":"https:\/\/myworldofit.net\/?p=10813","title":{"rendered":"PRTG REST API, PowerShell and UTF8"},"content":{"rendered":"An issue that I&#8217;ve now run into a few times now so I thought it was worth a blog post &#8211; if you are using the REST Custom sensor within PRTG Network Monitor you may see the error below if you have generated your REST configuration using PowerShell.\n\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-10815\" src=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Error.png\" alt=\"\" width=\"600\" height=\"100\" srcset=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Error.png 837w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Error-300x50.png 300w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Error-768x128.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/>\n<blockquote>XML: The returned XML does not match the expected schema. (code: PE233) &#8212; JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)<\/blockquote>\nThe cause is the default encoding from PowerShell is UCS-2 LE BOM as shown in Notepad++ below.\n\n<!-- \/wp:post-content -->\n\n<!-- wp:paragraph \/-->\n\n<!-- wp:image {\"id\":10815} \/-->\n\n<!-- wp:image {\"id\":10817} -->\n<figure class=\"wp-block-image\"><a href=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10817\" src=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working-1024x494.png\" alt=\"\" width=\"500\" height=\"241\" srcset=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working-1024x494.png 1024w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working-300x145.png 300w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working-768x370.png 768w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Not-working.png 1101w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:image {\"id\":10818} -->\n<figure><\/figure>\n<figure class=\"wp-block-image\"><\/figure>\nThe fix is simple in that when generating your REST configuration append -Encoding utf8 at the end of the Out-File command. I&#8217;ve also seen this apply to a few other situations when using PowerShell to output some form of text &#8211; in particular feeds for Palo Alto Networks Next Generation Firewalls.\n\n<!-- \/wp:image -->\n\n<!-- wp:image {\"id\":10816} -->\n<figure class=\"wp-block-image\"><a href=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Fix.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10816\" src=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Fix.png\" alt=\"\" width=\"600\" height=\"39\" srcset=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Fix.png 705w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Fix-300x20.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n<figure><\/figure>\n<figure><\/figure>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-10818\" src=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working-1024x494.png\" alt=\"\" width=\"500\" height=\"241\" srcset=\"https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working-1024x494.png 1024w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working-300x145.png 300w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working-768x370.png 768w, https:\/\/myworldofit.net\/wp-content\/uploads\/2019\/02\/Working.png 1101w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n<!-- \/wp:image -->","protected":false},"excerpt":{"rendered":"<p>An issue that I&#8217;ve now run into a few times now so I thought it was worth a blog post &#8211; if you are using the REST Custom sensor within PRTG Network Monitor you may see the error below if you have generated your REST configuration using PowerShell. XML: The returned XML does not match the expected schema. (code: PE233)&#8230; <a class=\"read-more\" href=\"https:\/\/myworldofit.net\/?p=10813\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[20],"tags":[495,248,197,384,524],"series":[],"class_list":["post-10813","post","type-post","status-publish","format-standard","hentry","category-software","tag-palo-alto-networks","tag-powershell","tag-prtg","tag-rest","tag-utf8"],"_links":{"self":[{"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/posts\/10813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myworldofit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10813"}],"version-history":[{"count":12,"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/posts\/10813\/revisions"}],"predecessor-version":[{"id":11172,"href":"https:\/\/myworldofit.net\/index.php?rest_route=\/wp\/v2\/posts\/10813\/revisions\/11172"}],"wp:attachment":[{"href":"https:\/\/myworldofit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myworldofit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myworldofit.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10813"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/myworldofit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=10813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}