Ready to get started?

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

Download Now

Automate Salesforce Einstein Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

Salesforce Einstein Analytics uses the OAuth 2 authentication standard. You will need to obtain the OAuthClientId and OAuthClientSecret by registering an app with Salesforce Einstein Analytics.

See the Getting Started section of the CData data provider documentation for an authentication guide.

PowerShell

  1. Install the module:

    Install-Module SFEinsteinAnalyticsCmdlets
  2. Connect:

    $sfeinsteinanalytics = Connect-SFEinsteinAnalytics -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL"
  3. Search for and retrieve data:

    $stagename = "Closed Won" $dataset_opportunity = Select-SFEinsteinAnalytics -Connection $sfeinsteinanalytics -Table "Dataset_Opportunity" -Where "StageName = `'$StageName`'" $dataset_opportunity

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

    $dataset_opportunity = Invoke-SFEinsteinAnalytics -Connection $sfeinsteinanalytics -Query 'SELECT * FROM Dataset_Opportunity WHERE StageName = @StageName' -Params @{'@StageName'='Closed Won'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsConnection("OAuthClientId=MyConsumerKey;OAuthClientSecret=MyConsumerSecret;CallbackURL=http://localhost:portNumber;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SFEinsteinAnalyticsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Name, CloseDate from Dataset_Opportunity" $da= New-Object System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.closedate }

Update Salesforce Einstein Data

PowerShell

Update-SFEinsteinAnalytics -Connection $SFEinsteinAnalytics -Columns @('Name','CloseDate') -Values @('MyName', 'MyCloseDate') -Table Dataset_Opportunity -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsCommand("UPDATE Dataset_Opportunity SET StageName='Closed Won' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Salesforce Einstein Data

PowerShell

Add-SFEinsteinAnalytics -Connection $SFEinsteinAnalytics -Table Dataset_Opportunity -Columns @("Name", "CloseDate") -Values @("MyName", "MyCloseDate")

ADO.NET

$cmd = New-Object System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsCommand("INSERT INTO Dataset_Opportunity (StageName) VALUES (@myStageName)", $conn) $cmd.Parameters.Add(new System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsParameter("@myStageName","Closed Won")) $cmd.ExecuteNonQuery()

Delete Salesforce Einstein Data

PowerShell

Remove-SFEinsteinAnalytics -Connection $SFEinsteinAnalytics -Table "Dataset_Opportunity" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsCommand("DELETE FROM Dataset_Opportunity WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.SFEinsteinAnalytics.SFEinsteinAnalyticsParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()