Ready to get started?

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

Download Now

Automate Dropbox Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

Dropbox uses the OAuth authentication standard. To authenticate using OAuth, you can use the embedded credentials or register an app with Dropbox.

See the Getting Started guide in the CData driver documentation for more information.

PowerShell

  1. Install the module:

    Install-Module DropboxCmdlets
  2. Connect:

    $dropbox = Connect-Dropbox
  3. Search for and retrieve data:

    $id = "1" $files = Select-Dropbox -Connection $dropbox -Table "Files" -Where "Id = `'$Id`'" $files

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

    $files = Invoke-Dropbox -Connection $dropbox -Query 'SELECT * FROM Files WHERE Id = @Id' -Params @{'@Id'='1'}

ADO.NET

  1. Load the provider's assembly:

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

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

    $sql="SELECT Id, Name from Files" $da= New-Object System.Data.CData.Dropbox.DropboxDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.name }

Update Dropbox Data

PowerShell

Update-Dropbox -Connection $Dropbox -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Files -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("UPDATE Files SET Id='1' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Dropbox.DropboxParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Dropbox Data

PowerShell

Add-Dropbox -Connection $Dropbox -Table Files -Columns @("Id", "Name") -Values @("MyId", "MyName")

ADO.NET

$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("INSERT INTO Files (Id) VALUES (@myId)", $conn) $cmd.Parameters.Add(new System.Data.CData.Dropbox.DropboxParameter("@myId","1")) $cmd.ExecuteNonQuery()

Delete Dropbox Data

PowerShell

Remove-Dropbox -Connection $Dropbox -Table "Files" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("DELETE FROM Files WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Dropbox.DropboxParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()