PowerShell – Getting oData in Powershell

Here and there you will get in contact with oData service providers.

The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for the web.

There are various kinds of libraries and tools can be used to consume OData services

This protocol allows you do make CRUD operations on the web data sources.

For the time being this will illustrated only the GET (READ) data features.

For example SharePoint is natively an oData provider.

But you can access a few Public oData providers. Here I will give you a few examples of oData.org public data sources.


If you go to this link above, you can see that it exposes a few services endpoints.

To consume these we will use PowerShell, of course Smile

Here we go :


$obj1 = Invoke-RestMethod -uri "http://services.odata.org/OData/OData.svc/Products?`$format=json"
$obj12.value | Select Name, Description, Price

This is the result :


Here is an other one to grab from oData


$url = "http://services.odata.org/v4/TripPinServiceRW/Airports"

$oOdata = Invoke-RestMethod -Uri $url 


This is the result :


As you can see it returns information of the Airports and apart from the “location” we see as well the “address” information.

Opposed to the first example above we will the COM like notation to access all data elements.

To retrieve the location data replace the .value by the below code.

# $oOdata.value


This is the result :


To retrieve the CountryRegion data replace the .location.city or just the Aiport Name by the below code.


write-host ""


This is the result :


This brings us to the fabulous LINQPad Tool that is able to consume oData sources


LINQPad can do a lot more that consuming oData sources. It was build to consume data sources using LINQ (Language-Integrated Query).

Unfortunately PowerShell can’t use LINQ natively.

See here for what Linq is about…

But you can use the PowerQuery add-in.  Winking smile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: