We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Automate SAP HANA XS Advanced Integration Tasks from PowerShell
Are you in search of a quick and easy way to access SAP HANA XS Advanced data from PowerShell? This article demonstrates how to utilize the SAP HANA XS Advanced Cmdlets for tasks like connecting to SAP HANA XS Advanced data, automating operations, downloading data, and more.
The CData Cmdlets for SAP HANA XS Advanced are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to SAP HANA XS Advanced.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to SAP HANA XS Advanced, but also an SQL interface; this tutorial shows how to use both to retrieve SAP HANA XS Advanced data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP HANA XS Advanced. To access SAP HANA XS Advanced data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP HANA XS Advanced.
Once you have acquired the necessary connection properties, accessing SAP HANA XS Advanced data in PowerShell can be enabled in three steps.
SAP HANA XSA uses the OAuth authentication standard. Before connecting, it is necessary to establish an SAP HANA XSA OData Service. See the OAuth section in the Help documentation for a guide.
PowerShell
-
Install the module:
Install-Module SAPHanaXSACmdlets
-
Connect:
$saphanaxsa = Connect-SAPHanaXSA -OAuthClientID "$OAuthClientID" -OAuthClientSecret "$OAuthClientSecret" -URL "$URL" -CallbackURL "$CallbackURL"
-
Search for and retrieve data:
$ = "" $ = Select-SAPHanaXSA -Connection $saphanaxsa -Table "" -Where " = `'$`'" $
You can also use the Invoke-SAPHanaXSA cmdlet to execute SQL commands:
$ = Invoke-SAPHanaXSA -Connection $saphanaxsa -Query 'SELECT * FROM WHERE = @' -Params @{'@'=''}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP HANA XS Advanced\lib\System.Data.CData.SAPHanaXSA.dll")
-
Connect to SAP HANA XS Advanced:
$conn= New-Object System.Data.CData.SAPHanaXSA.SAPHanaXSAConnection("OAuthClientID=my-ouath-client-id;OAuthClientSecret=my-oauth-client-secret;URL=https://hxehost:51027/euro.xsodata;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the SAPHanaXSADataAdapter, execute an SQL query, and output the results:
$sql="SELECT , from " $da= New-Object System.Data.CData.SAPHanaXSA.SAPHanaXSADataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_. $_. }