![]() |
VOOZH | about |
The CData Cmdlets for Smartsheet 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 Smartsheet.
CData provides the easiest way to access and integrate live data from Smartsheet. Customers use CData connectivity to:
Users frequently integrate Smartsheet with analytics tools such as Tableau, Crystal Reports, and Excel. Others leverage our tools to replicate Smartsheet data to databases or data warehouses.
The Cmdlets are not only a PowerShell interface to Smartsheet, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Smartsheet data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Smartsheet. To access Smartsheet data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Smartsheet.
Once you have acquired the necessary connection properties, accessing Smartsheet data in PowerShell can be enabled in three steps.
Smartsheet uses the OAuth authentication standard. To authenticate using OAuth, register an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties.
However, for testing purposes you can instead use the Personal Access Token you get when you create an application; set this to the OAuthAccessToken connection property.
Install the module:
Install-Module SmartsheetCmdlets
Connect:
$smartsheet = Connect-Smartsheet -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$assigned = "Ana Trujilo" $sheet_event_plan_budget = Select-Smartsheet -Connection $smartsheet -Table "Sheet_Event_Plan_Budget" -Where "Assigned = `'$Assigned`'" $sheet_event_plan_budget
You can also use the Invoke-Smartsheet cmdlet to execute SQL commands:
$sheet_event_plan_budget = Invoke-Smartsheet -Connection $smartsheet -Query 'SELECT * FROM Sheet_Event_Plan_Budget WHERE Assigned = @Assigned' -Params @{'@Assigned'='Ana Trujilo'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Smartsheet\lib\System.Data.CData.Smartsheet.dll")
Connect to Smartsheet:
$conn= New-Object System.Data.CData.Smartsheet.SmartsheetConnection("OAuthClientId=MyOauthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the SmartsheetDataAdapter, execute an SQL query, and output the results:
$sql="SELECT TaskName, Progress from Sheet_Event_Plan_Budget"
$da= New-Object System.Data.CData.Smartsheet.SmartsheetDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.taskname $_.progress
}
Update-Smartsheet -Connection $Smartsheet -Columns @('TaskName','Progress') -Values @('MyTaskName', 'MyProgress') -Table Sheet_Event_Plan_Budget -Id "MyId"
$cmd = New-Object System.Data.CData.Smartsheet.SmartsheetCommand("UPDATE Sheet_Event_Plan_Budget SET Assigned='Ana Trujilo' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Smartsheet.SmartsheetParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Smartsheet -Connection $Smartsheet -Table Sheet_Event_Plan_Budget -Columns @("TaskName", "Progress") -Values @("MyTaskName", "MyProgress")
$cmd = New-Object System.Data.CData.Smartsheet.SmartsheetCommand("INSERT INTO Sheet_Event_Plan_Budget (Assigned) VALUES (@myAssigned)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Smartsheet.SmartsheetParameter("@myAssigned","Ana Trujilo")))
$cmd.ExecuteNonQuery()
Remove-Smartsheet -Connection $Smartsheet -Table "Sheet_Event_Plan_Budget" -Id "MyId"
$cmd = New-Object System.Data.CData.Smartsheet.SmartsheetCommand("DELETE FROM Sheet_Event_Plan_Budget WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Smartsheet.SmartsheetParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Smartsheet Data Provider to get started:
Download NowLearn more:
👁 Smartsheet IconEasy-to-use Smartsheet client enables .NET-based applications to easily consume Smartsheet Sheets, Contacts, Folders, Groups, Users, etc.