Ready to get started?

Download a free trial of the SuiteCRM Data Provider to get started:

 Download Now

Learn more:

SuiteCRM Icon SuiteCRM ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with SuiteCRM account data including Leads, Contacts, Opportunities, Accounts, and more!

Automate SuiteCRM Integration Tasks from PowerShell



Are you in search of a quick and easy way to access SuiteCRM data from PowerShell? This article demonstrates how to utilize the SuiteCRM Cmdlets for tasks like connecting to SuiteCRM data, automating operations, downloading data, and more.

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

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing SuiteCRM data in PowerShell can be enabled in three steps.

The User and Password properties must be set to valid SuiteCRM user credentials. Additionally, specify the URL to the SuiteCRM application, for example http://suite.crm.com.

Note that retrieving SuiteCRM metadata can be expensive. It is advised that you store the metadata locally as described in the Caching Metadata section of the data provider help documentation.

PowerShell

  1. Install the module:

    Install-Module SuiteCRMCmdlets
  2. Connect:

    $suitecrm = Connect-SuiteCRM -URL "$URL" -User "$User" -Password "$Password"
  3. Search for and retrieve data:

    $industry = "Manufacturing" $accounts = Select-SuiteCRM -Connection $suitecrm -Table "Accounts" -Where "Industry = `'$Industry`'" $accounts

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

    $accounts = Invoke-SuiteCRM -Connection $suitecrm -Query 'SELECT * FROM Accounts WHERE Industry = @Industry' -Params @{'@Industry'='Manufacturing'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.SuiteCRM.SuiteCRMConnection("URL=http://mySuiteCRM.com;User=myUser;Password=myPassword;") $conn.Open()
  3. Instantiate the SuiteCRMDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Name, Industry from Accounts" $da= New-Object System.Data.CData.SuiteCRM.SuiteCRMDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.industry }

Update SuiteCRM Data

PowerShell

Update-SuiteCRM -Connection $SuiteCRM -Columns @('Name','Industry') -Values @('MyName', 'MyIndustry') -Table Accounts -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("UPDATE Accounts SET Industry='Manufacturing' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert SuiteCRM Data

PowerShell

Add-SuiteCRM -Connection $SuiteCRM -Table Accounts -Columns @("Name", "Industry") -Values @("MyName", "MyIndustry")

ADO.NET

$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("INSERT INTO Accounts (Industry) VALUES (@myIndustry)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myIndustry","Manufacturing"))) $cmd.ExecuteNonQuery()

Delete SuiteCRM Data

PowerShell

Remove-SuiteCRM -Connection $SuiteCRM -Table "Accounts" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("DELETE FROM Accounts WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()