I've used Fiddler to compare the request from PowerShell and a request from a browser.
// PowerShell
GET /OData/OData.svc/Advertisements?=json HTTP/1.1
// Browser
GET /OData/OData.svc/Advertisements?$format=json HTTP/1.1
As you can see, the $format
gets stripped from the URL and you will get an atom+xml
response (just like requesting http://services.odata.org/OData/OData.svc/Advertisements
, so without any URL parameters):
Content-Type: application/atom+xml;type=feed;charset=utf-8
In order to solve the problem, you need to escape the $
when you are using PowerShell.
Try this:
$obj = Invoke-RestMethod -uri "http://services.odata.org/OData/OData.svc/Advertisements?`$format=json"
$obj.value
The output (as you expected):
ID Name AirDate
-- ---- -------
f89dee73-af9f-4cd4-b330-db93c25ff3c7 Old School Lemonade Store, Retro Style 2012-11-07T00:00:00
db2d2186-1c29-4d1e-88ef-a127f521b9c6 Early morning start, need coffee 2000-02-29T00:00:00