Automate Cassandra Integration Tasks from PowerShell

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

The CData ADO.NET Provider for Cassandra 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 Cassandra.

ADO.NET Provider

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

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

Set the Server, Port, and Database connection properties to connect to Cassandra. Additionally, to use internal authentication set the User and Password connection properties.

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Cassandra.CassandraConnection("Database=MyCassandraDB;Port=7000;Server=127.0.0.1;")
    $conn.Open()
  3. Instantiate the CassandraDataAdapter, execute an SQL query, and output the results:

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

Update Cassandra Data

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

Insert Cassandra Data

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

Delete Cassandra Data

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

Ready to get started?

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

 Download Now

Learn more:

Apache Cassandra Icon Cassandra ADO.NET Provider

Connect .NET applications with the Cassandra real-time NoSQL cloud database service. Use Apache Cassandra as the big data backend that powers your .NET applications.