Ready to get started?

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

Download Now

Automate DigitalOcean Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

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

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

PowerShell

  1. Install the module:

    Install-Module DigitalOceanCmdlets
  2. Connect:

    $digitalocean = Connect-DigitalOcean
  3. Search for and retrieve data:

    $id = "1" $droplets = Select-DigitalOcean -Connection $digitalocean -Table "Droplets" -Where "Id = `'$Id`'" $droplets

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

    $droplets = Invoke-DigitalOcean -Connection $digitalocean -Query 'SELECT * FROM Droplets 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 DigitalOcean\lib\System.Data.CData.DigitalOcean.dll")
  2. Connect to DigitalOcean:

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

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

Update DigitalOcean Data

PowerShell

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

ADO.NET

$cmd = New-Object System.Data.CData.DigitalOcean.DigitalOceanCommand("UPDATE Droplets SET Id='1' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.DigitalOcean.DigitalOceanParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert DigitalOcean Data

PowerShell

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

ADO.NET

$cmd = New-Object System.Data.CData.DigitalOcean.DigitalOceanCommand("INSERT INTO Droplets (Id) VALUES (@myId)", $conn) $cmd.Parameters.Add(new System.Data.CData.DigitalOcean.DigitalOceanParameter("@myId","1")) $cmd.ExecuteNonQuery()

Delete DigitalOcean Data

PowerShell

Remove-DigitalOcean -Connection $DigitalOcean -Table "Droplets" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.DigitalOcean.DigitalOceanCommand("DELETE FROM Droplets WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.DigitalOcean.DigitalOceanParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()