Ready to get started?

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

Download Now

Automate TSheets Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

TSheets uses the OAuth2 standard for authentication and authorization. To construct your own OAuth app and connect to data, refer to OAuth section in the Help.

PowerShell

  1. Install the module:

    Install-Module TSheetsCmdlets
  2. Connect:

    $tsheets = Connect-TSheets -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackUrl "$CallbackUrl"
  3. Search for and retrieve data:

    $jobcodetype = "regular" $timesheets = Select-TSheets -Connection $tsheets -Table "Timesheets" -Where "JobCodeType = `'$JobCodeType`'" $timesheets

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

    $timesheets = Invoke-TSheets -Connection $tsheets -Query 'SELECT * FROM Timesheets WHERE JobCodeType = @JobCodeType' -Params @{'@JobCodeType'='regular'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.TSheets.TSheetsConnection("OAuthClientId=myclientid;OAuthClientSecret=myclientsecret;CallbackUrl=http://localhost:33333;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the TSheetsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, JobcodeId from Timesheets" $da= New-Object System.Data.CData.TSheets.TSheetsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.jobcodeid }