As the COVID-19 situation continues to evolve and organizations are having to adjust, Alert Logic is here for you, 24/7. Learn More

How can I access the API with a PowerShell script using the Invoke-WebRequest command?



  • Avatar
    Evan Cunningham

    For some Powershell users consider using...

       $headers = @{}

       $headers.Add("Accept","application/json" )


    ...technique for adding headers individually. the example as provided is potentially flawed, with PS not recognizing the reserved word Authorization as a valid value for the array.

    Adding them separately worked for me.



    Comment actions Permalink
  • Avatar
    Abby Kincer

    Thanks for sharing this, Evan! We're going to run it by our technical support team to see if it's valuable to add into the article. Your feedback is much appreciated.

    Comment actions Permalink
  • Avatar
    Welly Siauw

    In case you would like to see the entire response, please consider to add -Depth to the last command in the pipe:

    Invoke-WebRequest -uri $RemoteHost -Headers &headers | ConvertFrom-Json | ConvertTo-JSON -Depth 5

    Comment actions Permalink

Please sign in to leave a comment.