Automate SAP HANA Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:


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

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

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

Cmdlets or ADO.NET?

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

After obtaining the needed connection properties, accessing SAP HANA data in PowerShell consists of three basic 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. Install the module:

    Install-Module SAPHANACmdlets
  2. Connect:

    $saphana = Connect-SAPHANA -User "$User" -Password "$Password" -Server "$Server" -Database "$Database"
  3. Search for and retrieve data:

    $name = "TestBucket" $buckets = Select-SAPHANA -Connection $saphana -Table "Buckets" -Where "Name = `'$Name`'" $buckets

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

    $buckets = Invoke-SAPHANA -Connection $saphana -Query 'SELECT * FROM Buckets WHERE Name = @Name' -Params @{'@Name'='TestBucket'}


  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 $ $_.ownerid }

Update SAP HANA Data


Update-SAPHANA -Connection $SAPHANA -Columns @('Name','OwnerId') -Values @('MyName', 'MyOwnerId') -Table Buckets -Id "MyId"


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

Insert SAP HANA Data


Add-SAPHANA -Connection $SAPHANA -Table Buckets -Columns @("Name", "OwnerId") -Values @("MyName", "MyOwnerId")


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

Delete SAP HANA Data


Remove-SAPHANA -Connection $SAPHANA -Table "Buckets" -Id "MyId"


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