Automate Couchbase Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access Couchbase data from PowerShell? This article demonstrates how to utilize the Couchbase Cmdlets for tasks like connecting to Couchbase data, automating operations, downloading data, and more.

The CData ADO.NET Provider for Couchbase is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Couchbase.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Couchbase; this tutorial shows how to use the Provider to create, retrieve, update, and delete Couchbase data.

Once you have acquired the necessary connection properties, accessing Couchbase data in PowerShell can be enabled in three steps.

To connect using the Login method, set User, Password, and Server to the credentials for the account and the address of the server you want to connect to.

  1. Load the provider's assembly:

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

     
    $conn= New-Object System.Data.CData.Couchbase.CouchbaseConnection("User=myuseraccount;Password=mypassword;Server=http://mycouchbaseserver;")
    $conn.Open()
    
  3. Instantiate the CouchbaseDataAdapter, execute an SQL query, and output the results:

    
    $sql="SELECT FirstName, TotalDue from Customer"
    
    $da= New-Object System.Data.CData.Couchbase.CouchbaseDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_.firstname $_.totaldue
    }
      

Update Couchbase Data


$cmd =  New-Object System.Data.CData.Couchbase.CouchbaseCommand("UPDATE Customer SET FirstName='Bob' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert Couchbase Data


$cmd =  New-Object System.Data.CData.Couchbase.CouchbaseCommand("INSERT INTO Customer (FirstName) VALUES (@myFirstName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myFirstName","Bob")))
$cmd.ExecuteNonQuery()

Delete Couchbase Data


$cmd =  New-Object System.Data.CData.Couchbase.CouchbaseCommand("DELETE FROM Customer WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Couchbase.CouchbaseParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

Download a free trial of the Couchbase Data Provider to get started:

 Download Now

Learn more:

Couchbase Icon Couchbase ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Couchbase.