Get Request in Postman works but not in Powershell Code

m0d3r Source

I am having several issues. When I do a simple Get request in Postman I get the desired results and JSON object. However when I do a request in Powershell my output file is incomplete and not all the data is there. I get no errors when running my Powershell code, just incomplete data.

What am I doing wrong in my Powershell code? Is there any ideas of what I could be doing wrong in general?

$response = Invoke-RestMethod -Uri "$($privateApiUrl)/api/public/v1/students?" -Headers $headers -Method Get -ErrorVariable RestError -ErrorAction SilentlyContinue

if ($RestError)
    $HttpStatusCode = $RestError.ErrorRecord.Exception.Response.StatusCode.value__
    $HttpStatusDescription = $RestError.ErrorRecord.Exception.Response.StatusDescription

    Throw "Http Status Code: $($HttpStatusCode) `nHttp Status Description: $($HttpStatusDescription)"
else {

    $response | Out-File -FilePath C:\SQL\response3.txt



answered 5 months ago SomewhatStudent #1

I know this is about 3 months late, but I just had something similar and all I had to do is this:

convertTo-json $Response | Out-file -FilePath "C:\SQL\response3.txt"

comments powered by Disqus