![]() |
VOOZH | about |
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.
The Cmdlets are not only a PowerShell interface to Dropbox, 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.
Once you have acquired the necessary connection properties, accessing Dropbox data in PowerShell can be enabled in three 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.
Install the module:
Install-Module DropboxCmdlets
Connect:
$dropbox = Connect-Dropbox -InitiateOAuth "$InitiateOAuth"
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'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Dropbox\lib\System.Data.CData.Dropbox.dll")
Connect to Dropbox:
$conn= New-Object System.Data.CData.Dropbox.DropboxConnection("InitiateOAuth=GETANDREFRESH;")
$conn.Open()
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 -Connection $Dropbox -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Files -Id "MyId"
$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("UPDATE Files SET Id='1' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dropbox.DropboxParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Dropbox -Connection $Dropbox -Table Files -Columns @("Id", "Name") -Values @("MyId", "MyName")
$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("INSERT INTO Files (Id) VALUES (@myId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dropbox.DropboxParameter("@myId","1")))
$cmd.ExecuteNonQuery()
Remove-Dropbox -Connection $Dropbox -Table "Files" -Id "MyId"
$cmd = New-Object System.Data.CData.Dropbox.DropboxCommand("DELETE FROM Files WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dropbox.DropboxParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Dropbox Data Provider to get started:
Download NowLearn more:
👁 Dropbox IconRapidly create and deploy powerful .NET applications that integrate with Dropbox file storage data including Files, Folders, Users, and more!