Automate Salesforce Data Cloud Integration Tasks from PowerShell



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

The CData Cmdlets for Salesforce Data Cloud are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Salesforce Data Cloud.

PowerShell Cmdlets or ADO.NET Provider?

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

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

Salesforce Data Cloud supports authentication via the OAuth standard.

OAuth

Set AuthScheme to OAuth.

Desktop Applications

CData provides an embedded OAuth application that simplifies authentication at the desktop.

You can also authenticate from the desktop via a custom OAuth application, which you configure and register at the Salesforce Data Cloud console. For further information, see Creating a Custom OAuth App in the Help documentation.

Before you connect, set these properties:

  • InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • OAuthClientId (custom applications only): The Client ID assigned when you registered your custom OAuth application.
  • OAuthClientSecret (custom applications only): The Client Secret assigned when you registered your custom OAuth application.

When you connect, the driver opens Salesforce Data Cloud's OAuth endpoint in your default browser. Log in and grant permissions to the application.

The driver then completes the OAuth process as follows:

  • Extracts the access token from the callback URL.
  • Obtains a new access token when the old one expires.
  • Saves OAuth values in OAuthSettingsLocation so that they persist across connections.
  • For other OAuth methods, including Web Applications and Headless Machines, refer to the Help documentation.

    PowerShell

    1. Install the module:

      Install-Module SalesforceDataCloudCmdlets
    2. Connect:

      $salesforcedatacloud = Connect-SalesforceDataCloud
    3. Search for and retrieve data:

      $employeecount = "250" $account = Select-SalesforceDataCloud -Connection $salesforcedatacloud -Table "Account" -Where "EmployeeCount = `'$EmployeeCount`'" $account

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

      $account = Invoke-SalesforceDataCloud -Connection $salesforcedatacloud -Query 'SELECT * FROM Account WHERE EmployeeCount = @EmployeeCount' -Params @{'@EmployeeCount'='250'}

    ADO.NET

    1. Load the provider's assembly:

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

      $conn= New-Object System.Data.CData.SalesforceDataCloud.SalesforceDataCloudConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
    3. Instantiate the SalesforceDataCloudDataAdapter, execute an SQL query, and output the results:

      $sql="SELECT [Account ID], [Account Name] from Account" $da= New-Object System.Data.CData.SalesforceDataCloud.SalesforceDataCloudDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.[account id] $_.[account name] }

Ready to get started?

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

 Download Now

Learn more:

Salesforce Data Cloud Icon Salesforce Data Cloud ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Salesforce Data Cloud.