Ready to get started?

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

 Download Now

Learn more:

HarperDB Icon HarperDB ADO.NET Provider

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

Automate HarperDB Integration Tasks from PowerShell



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

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

PowerShell Cmdlets or ADO.NET Provider?

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

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

Set the Server, User, and Password connection properties to connect to HarperDB. Set UseSSL to secure connections with TLS/SSL.

PowerShell

  1. Install the module:

    Install-Module HarperDBCmdlets
  2. Connect:

    $harperdb = Connect-HarperDB -Server "$Server" -User "$User" -Password "$Password"
  3. Search for and retrieve data:

    $country = "US" $customers = Select-HarperDB -Connection $harperdb -Table "Customers" -Where "Country = `'$Country`'" $customers

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

    $customers = Invoke-HarperDB -Connection $harperdb -Query 'SELECT * FROM Customers WHERE Country = @Country' -Params @{'@Country'='US'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.HarperDB.HarperDBConnection("Server=127.0.0.1;User=admin;Password=1234;") $conn.Open()
  3. Instantiate the HarperDBDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT City, CompanyName from Customers" $da= New-Object System.Data.CData.HarperDB.HarperDBDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.city $_.companyname }

Update HarperDB Data

PowerShell

Update-HarperDB -Connection $HarperDB -Columns @('City','CompanyName') -Values @('MyCity', 'MyCompanyName') -Table Customers -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.HarperDB.HarperDBCommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.HarperDB.HarperDBParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert HarperDB Data

PowerShell

Add-HarperDB -Connection $HarperDB -Table Customers -Columns @("City", "CompanyName") -Values @("MyCity", "MyCompanyName")

ADO.NET

$cmd = New-Object System.Data.CData.HarperDB.HarperDBCommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.HarperDB.HarperDBParameter("@myCountry","US"))) $cmd.ExecuteNonQuery()

Delete HarperDB Data

PowerShell

Remove-HarperDB -Connection $HarperDB -Table "Customers" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.HarperDB.HarperDBCommand("DELETE FROM Customers WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.HarperDB.HarperDBParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()