Ready to get started?

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

Download Now

Automate Act CRM Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

The User and Password properties, under the Authentication section, must be set to valid Act! user credentials. In addition to the authentication values, see the following:

  • Connecting to Act! Premium

    In addition to the authentication values, the URL to Act! is also required; for example https://eup1-iis-04.eu.hosted.act.com/.

    Additionally, you must specify the ActDatabase you will connect to. This is found by going to the About Act! Premium menu of your account, at the top right of the page, in the ? menu. Use the Database Name in the window that appears.

  • Connecting to Act! Premium Cloud

    To connect to your Act! Premium Cloud account, you also need to specify the ActCloudName property. This property is found in the URL address of the Cloud account; for example https://eup1-iis-04.eu.hosted.act.com/ActCloudName/.

Note that retrieving ActCRM metadata can be expensive. It is advised that you set the CacheMetadata property to store the metadata locally.

PowerShell

  1. Install the module:

    Install-Module ActCRMCmdlets
  2. Connect:

    $actcrm = Connect-ActCRM -URL "$URL" -User "$User" -Password "$Password" -ActDatabase "$ActDatabase"
  3. Search for and retrieve data:

    $subject = "Sample subject" $activities = Select-ActCRM -Connection $actcrm -Table "Activities" -Where "Subject = `'$Subject`'" $activities

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

    $activities = Invoke-ActCRM -Connection $actcrm -Query 'SELECT * FROM Activities WHERE Subject = @Subject' -Params @{'@Subject'='Sample subject'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.ActCRM.ActCRMConnection("URL=https://myActCRMserver.com;User=myUser;Password=myPassword;ActDatabase=MyDB;") $conn.Open()
  3. Instantiate the ActCRMDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ActivityDisplayName, Subject from Activities" $da= New-Object System.Data.CData.ActCRM.ActCRMDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.activitydisplayname $_.subject }

Update Act CRM Data

PowerShell

Update-ActCRM -Connection $ActCRM -Columns @('ActivityDisplayName','Subject') -Values @('MyActivityDisplayName', 'MySubject') -Table Activities -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.ActCRM.ActCRMCommand("UPDATE Activities SET Subject='Sample subject' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.ActCRM.ActCRMParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Act CRM Data

PowerShell

Add-ActCRM -Connection $ActCRM -Table Activities -Columns @("ActivityDisplayName", "Subject") -Values @("MyActivityDisplayName", "MySubject")

ADO.NET

$cmd = New-Object System.Data.CData.ActCRM.ActCRMCommand("INSERT INTO Activities (Subject) VALUES (@mySubject)", $conn) $cmd.Parameters.Add(new System.Data.CData.ActCRM.ActCRMParameter("@mySubject","Sample subject")) $cmd.ExecuteNonQuery()

Delete Act CRM Data

PowerShell

Remove-ActCRM -Connection $ActCRM -Table "Activities" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.ActCRM.ActCRMCommand("DELETE FROM Activities WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.ActCRM.ActCRMParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()