Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →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
-
Install the module:
Install-Module SuiteCRMCmdlets
-
Connect:
$suitecrm = Connect-SuiteCRM -URL "$URL" -User "$User" -Password "$Password"
-
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
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SuiteCRM\lib\System.Data.CData.SuiteCRM.dll")
-
Connect to SuiteCRM:
$conn= New-Object System.Data.CData.SuiteCRM.SuiteCRMConnection("URL=http://mySuiteCRM.com;User=myUser;Password=myPassword;") $conn.Open()
-
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()
CodeProject