Is there a way to store the return code somewhere when calling Invoke-RestMethod
in PowerShell?
My code looks like this:
$url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/Adventure?key=MyKeyGoesHere"
$XMLReturned = Invoke-RestMethod -Uri $url -Method Get;
I don't see anywhere in my $XMLReturned
variable a return code of 200. Where can I find that return code?
Invoke-WebRequest
is the way to go; it's not "old"; and it doesn't requiretry
/catch
or an exception. You might want to edit the answer a bit to show that, and to explain thatInvoke-RestMethod
just converts the content from JSON to object automatically, which can be achieved withiwr
by piping the content toConvertFrom-Json
. – Fawkes