Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Tableau CRM Analytics Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Tableau CRM Analytics data from PowerShell? This article demonstrates how to utilize the Tableau CRM Analytics Cmdlets for tasks like connecting to Tableau CRM Analytics data, automating operations, downloading data, and more.
The CData Cmdlets for Tableau CRM Analytics 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 Tableau CRM Analytics.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Tableau CRM Analytics, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Tableau CRM Analytics data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Tableau CRM Analytics. To access Tableau CRM Analytics data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Tableau CRM Analytics.
Once you have acquired the necessary connection properties, accessing Tableau CRM Analytics data in PowerShell can be enabled in three steps.
Tableau CRM Analytics uses the OAuth 2 authentication standard. You will need to obtain the OAuthClientId and OAuthClientSecret by registering an app with Tableau CRM Analytics.
See the Getting Started section of the Help documentation for an authentication guide.
PowerShell
-
Install the module:
Install-Module TableauCRMCmdlets
-
Connect:
$tableaucrm = Connect-TableauCRM -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL"
-
Search for and retrieve data:
$stagename = "Closed Won" $dataset_opportunity = Select-TableauCRM -Connection $tableaucrm -Table "Dataset_Opportunity" -Where "StageName = `'$StageName`'" $dataset_opportunity
You can also use the Invoke-TableauCRM cmdlet to execute SQL commands:
$dataset_opportunity = Invoke-TableauCRM -Connection $tableaucrm -Query 'SELECT * FROM Dataset_Opportunity WHERE StageName = @StageName' -Params @{'@StageName'='Closed Won'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Tableau CRM Analytics\lib\System.Data.CData.TableauCRM.dll")
-
Connect to Tableau CRM Analytics:
$conn= New-Object System.Data.CData.TableauCRM.TableauCRMConnection("OAuthClientId=MyConsumerKey;OAuthClientSecret=MyConsumerSecret;CallbackURL=http://localhost:portNumber;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the TableauCRMDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, CloseDate from Dataset_Opportunity" $da= New-Object System.Data.CData.TableauCRM.TableauCRMDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.closedate }
Update Tableau CRM Analytics Data
PowerShell
Update-TableauCRM -Connection $TableauCRM -Columns @('Name','CloseDate') -Values @('MyName', 'MyCloseDate') -Table Dataset_Opportunity -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.TableauCRM.TableauCRMCommand("UPDATE Dataset_Opportunity SET StageName='Closed Won' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.TableauCRM.TableauCRMParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Tableau CRM Analytics Data
PowerShell
Add-TableauCRM -Connection $TableauCRM -Table Dataset_Opportunity -Columns @("Name", "CloseDate") -Values @("MyName", "MyCloseDate")
ADO.NET
$cmd = New-Object System.Data.CData.TableauCRM.TableauCRMCommand("INSERT INTO Dataset_Opportunity (StageName) VALUES (@myStageName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.TableauCRM.TableauCRMParameter("@myStageName","Closed Won")))
$cmd.ExecuteNonQuery()
Delete Tableau CRM Analytics Data
PowerShell
Remove-TableauCRM -Connection $TableauCRM -Table "Dataset_Opportunity" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.TableauCRM.TableauCRMCommand("DELETE FROM Dataset_Opportunity WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.TableauCRM.TableauCRMParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject