Automate SAP HANA Integration Tasks from PowerShell

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

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

ADO.NET Provider

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

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

Set the Server, Database and Port properties to specify the address of your SAP Hana database to interact with. Set the User and the Password properties to authenticate to the server.

  1. Load the provider's assembly:

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

     
    $conn= New-Object System.Data.CData.SAPHANA.SAPHANAConnection("User=system;Password=mypassword;Server=localhost;Database=systemdb;")
    $conn.Open()
    
  3. Instantiate the SAPHANADataAdapter, execute an SQL query, and output the results:

    
    $sql="SELECT Name, OwnerId from Buckets"
    
    $da= New-Object System.Data.CData.SAPHANA.SAPHANADataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_.name $_.ownerid
    }
      

Update SAP HANA Data


$cmd =  New-Object System.Data.CData.SAPHANA.SAPHANACommand("UPDATE Buckets SET Name='TestBucket' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert SAP HANA Data


$cmd =  New-Object System.Data.CData.SAPHANA.SAPHANACommand("INSERT INTO Buckets (Name) VALUES (@myName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myName","TestBucket")))
$cmd.ExecuteNonQuery()

Delete SAP HANA Data


$cmd =  New-Object System.Data.CData.SAPHANA.SAPHANACommand("DELETE FROM Buckets WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

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

 Download Now

Learn more:

SAP HANA Icon SAP HANA ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with SAP HANA.