Ready to get started?

Learn more about the CData ADO.NET Provider for Odoo or download a free trial:

Download Now

Automate Odoo Integration Tasks from PowerShell

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

The CData Cmdlets for Odoo 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 Odoo.

Cmdlets or ADO.NET?

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

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

To connect, set the Url to a valid Odoo site, User and Password to the connection details of the user you are connecting with, and Database to the Odoo database.

PowerShell

  1. Install the module:

    Install-Module OdooCmdlets
  2. Connect:

    $odoo = Connect-Odoo -User "$User" -Password "$Password" -URL "$URL" -Database "$Database"
  3. Search for and retrieve data:

    $id = "1" $res_users = Select-Odoo -Connection $odoo -Table "res_users" -Where "id = `'$id`'" $res_users

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

    $res_users = Invoke-Odoo -Connection $odoo -Query 'SELECT * FROM res_users WHERE id = @id' -Params @{'@id'='1'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Odoo.OdooConnection("User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase;") $conn.Open()
  3. Instantiate the OdooDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT name, email from res_users" $da= New-Object System.Data.CData.Odoo.OdooDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.email }

Update Odoo Data

PowerShell

Update-Odoo -Connection $Odoo -Columns @('name','email') -Values @('Myname', 'Myemail') -Table res_users -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Odoo.OdooCommand("UPDATE res_users SET id='1' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Odoo.OdooParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Odoo Data

PowerShell

Add-Odoo -Connection $Odoo -Table res_users -Columns @("name", "email") -Values @("Myname", "Myemail")

ADO.NET

$cmd = New-Object System.Data.CData.Odoo.OdooCommand("INSERT INTO res_users (id) VALUES (@myid)", $conn) $cmd.Parameters.Add(new System.Data.CData.Odoo.OdooParameter("@myid","1")) $cmd.ExecuteNonQuery()

Delete Odoo Data

PowerShell

Remove-Odoo -Connection $Odoo -Table "res_users" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Odoo.OdooCommand("DELETE FROM res_users WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Odoo.OdooParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()