2

I have now wasted a lot of time on this just can't see what I'm doing wrong I have looked all over the net and a lot of PowerShell guides use this and the examples work fine on my end as well but when I try this on my data it does not work...

$response = Invoke-WebRequest -Uri $APIURLaction -Headers $headers -Method $action -UseBasicParsing
$response
$response | Select-Object -Expand Content

Outputs

StatusCode        : 200
StatusDescription : OK
Content           : {"clientProperties":[{"clientProps":{"iSCSIPort":3260,"clusterType":0},"client":{"evmgrcPort":0,"cvdPort":8400,"clientEntity":
                    {"hostName":"CommServe","clientId":2,"clientName":"commserve","_typ...
RawContent        : HTTP/1.1 200 OK
                    Content-Length: 267
                    Content-Type: application/json; charset=utf-8
                    Date: Mon, 15 Oct 2018 11:48:26 GMT
                    Server: Microsoft-IIS/10.0
                    X-Powered-By: ASP.NET

                    {"clientProperties":[{...
Forms             :
Headers           : {[Content-Length, 267], [Content-Type, application/json; charset=utf-8], [Date, Mon, 15 Oct 2018 11:48:26 GMT], [Server,
                    Microsoft-IIS/10.0]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        :
RawContentLength  : 267

}hostName":"CommServe","clientId":2,"clientName":"commserve","_type_":3,"clientGUID":"6D658775-D8C1-4D1D-8D0A-42702AB75A63"

and as you can clearly see | Select-Object -Expand Content does not return the content only the last line... the same goes for $response.Content :(

And I can not figure out why hope you can help

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 2
    Sort-of unrelated to the question, but `Invoke-RestMethod` should take care of parsing the JSON into a PowerShell object on the fly, should that be what you need. – Jeroen Mostert Oct 15 '18 at 12:03
  • 1
    Perhaps the string only _appears_ to be single-line on output due to embedded isolated CR characters or other hidden control chars.; inspect it character by character, as demonstrated [here](https://stackoverflow.com/a/52648684/45375), for example. – mklement0 Oct 15 '18 at 13:25

0 Answers0