Automate REST Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:


Rapidly create and deploy powerful .NET applications that integrate with REST web services.

Are you looking for a quick and easy way to access REST data from PowerShell? We show how to use the Cmdlets for REST and the CData ADO.NET Provider for REST to connect to REST data and synchronize, automate, download, and more.

The CData Cmdlets for REST are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to REST.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the REST API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete REST data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for REST. To access REST data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for REST.

After obtaining the needed connection properties, accessing REST data in PowerShell consists of three basic steps.

See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models REST APIs as bidirectional database tables and XML/JSON files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.

After setting the URI and providing any authentication values, set Format to "XML" or "JSON" and set DataModel to more closely match the data representation to the structure of your data.

The DataModel property is the controlling property over how your data is represented into tables and toggles the following basic configurations.

  • Document (default): Model a top-level, document view of your REST data. The data provider returns nested elements as aggregates of data.
  • FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
  • Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.

See the Modeling REST Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.


  1. Install the module:

    Install-Module RESTCmdlets
  2. Connect:

    $rest = Connect-REST -DataModel "$DataModel" -URI "$URI" -Format "$Format"
  3. Search for and retrieve data:

    $[ ] = "Roberts" $people = Select-REST -Connection $rest -Table "people" -Where "[ ] = `'$[ ]`'" $people

    You can also use the Invoke-REST cmdlet to execute SQL commands:

    $people = Invoke-REST -Connection $rest -Query 'SELECT * FROM people WHERE [ ] = @[ ]' -Params @{'@[ ]'='Roberts'}


  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for REST\lib\System.Data.CData.REST.dll")
  2. Connect to REST:

    $conn= New-Object System.Data.CData.REST.RESTConnection("DataModel=Relational;URI=C:/people.xml;Format=XML;") $conn.Open()
  3. Instantiate the RESTDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT [ ], [ ] from people" $da= New-Object System.Data.CData.REST.RESTDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.[ ] $_.[ ] }

Update REST Data


Update-REST -Connection $REST -Columns @('[ ]','[ ]') -Values @('My[ ]', 'My[ ]') -Table people -Id "MyId"


$cmd = New-Object System.Data.CData.REST.RESTCommand("UPDATE people SET [ ]='Roberts' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.REST.RESTParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert REST Data


Add-REST -Connection $REST -Table people -Columns @("[ ]", "[ ]") -Values @("My[ ]", "My[ ]")


$cmd = New-Object System.Data.CData.REST.RESTCommand("INSERT INTO people ([ ]) VALUES (@my[ ])", $conn) $cmd.Parameters.Add(new System.Data.CData.REST.RESTParameter("@my[ ]","Roberts")) $cmd.ExecuteNonQuery()

Delete REST Data


Remove-REST -Connection $REST -Table "people" -Id "MyId"


$cmd = New-Object System.Data.CData.REST.RESTCommand("DELETE FROM people WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.REST.RESTParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()