Cmdlets for Act! CRM

Build 24.0.8963

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our ActCRM Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module ActCRMCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module ActCRMCmdlets;

You can then use the Connect-ActCRM cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-ActCRM -URL 'https://myActCRMserver.com' -User 'myUser' -Password 'myPassword' -ActDatabase 'MyActDB

Connecting to Act! CRM

You can connect to either Act! CRM or Act! Premium Cloud. Set the following to connect:

  • User: The username used to authenticate to the Act! database.
  • Password: The password used to authenticate to the Act! database.
  • URL: The URL where the Act! CRM account is hosted. For example: http://serverName/.
  • ActDatabase: The name of the Act! database you want to connect to. This is found by going to the About Act! Premium menu of your account, found at the top right of the page, in the ? menu. Use the Database Name in the window that appears.
  • ActCloudRegion (Act! Premium Cloud only): The Region of the Act! Premium Cloud account.

Caching Metadata

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

Retrieving Data

The Select-ActCRM cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-ActCRM -Connection $conn -Table "Activities" -Columns @("FullName, Company") -Where "FullName='Anna'"
The Invoke-ActCRM cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-ActCRM -Connection $conn -Table Activities -Where "FullName = 'Anna'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myActivitiesData.csv -NoTypeInformation

You will notice that we piped the results from Select-ActCRM into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-ActCRM -URL 'https://myActCRMserver.com' -User 'myUser' -Password 'myPassword' -ActDatabase 'MyActDB
PS C:\> $row = Select-ActCRM -Connection $conn -Table "Activities" -Columns (FullName, Company) -Where "FullName = 'Anna'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "Activities",
  "Columns":  [

  ],
  "FullName":  "MyFullName",
  "Company":  "MyCompany"
} 

Deleting Data

The following line deletes any records that match the criteria:

Select-ActCRM -Connection $conn -Table Activities -Where "FullName = 'Anna'" | Remove-ActCRM

Modifying Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Act! CRM, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyActivitiesUpdates.csv | %{
  $record = Select-ActCRM -Connection $conn -Table Activities -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-ActCRM -Connection $conn -Table Activities -Columns @("FullName","Company") -Values @($_.FullName, $_.Company) -Where "Id  = `'$_.Id`'"
  }else{
    Add-ActCRM -Connection $conn -Table Activities -Columns @("FullName","Company") -Values @($_.FullName, $_.Company)
  }
}

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.8963