Automate SAP Integration Tasks from PowerShell

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

The CData ADO.NET Provider for SAP is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to SAP.

About SAP Data Integration

CData provides the easiest way to access and integrate live data from SAP. Customers use CData connectivity to:

  • Access every edition of SAP, including SAP R/3, SAP NetWeaver, SAP ERP / ECC 6.0, and SAP S/4 HANA on premises data that is exposed by the RFC.
  • Perform actions like sending IDoc or IDoc XML files to the server and creating schemas for functions or queries through SQL stored procedures.
  • Connect optimally depending on where a customer's SAP instance is hosted.

While most users leverage our tools to replicate SAP data to databases or data warehouses, many also integrate live SAP data with analytics tools such as Tableau, Power BI, and Excel.


Getting Started


ADO.NET Provider

The ADO.NET Provider provides a SQL interface for SAP; this tutorial shows how to use the Provider to retrieve SAP data.

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

You can connect to SAP systems using either librfc32.dll, librfc32u.dll, NetWeaver, or Web Services (SOAP). Set the ConnectionType connection property to CLASSIC (librfc32.dll), CLASSIC_UNICODE (librfc32u.dll), NETWEAVER, or SOAP.

If you are using the SOAP interface, set the Client, RFCUrl, SystemNumber, User, and Password properties, under the Authentication section.

Otherwise, set Host, User, Password, Client, and SystemNumber.

Note: We do not distribute the librfc32.dll or other SAP assemblies. You must find them from your SAP installation and install them on your machine.

For more information, see this guide on obtaining the connection properties needed to connect to any SAP system.

  1. Load the provider's assembly:

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

     
    $conn= New-Object System.Data.CData.SAPERP.SAPERPConnection("Host=sap.mydomain.com;User=EXT90033;Password=xxx;Client=800;System Number=09;ConnectionType=Classic;Location=C:/mysapschemafolder;")
    $conn.Open()
    
  3. Instantiate the SAPERPDataAdapter, execute an SQL query, and output the results:

    
    $sql="SELECT MANDT, MBRSH from MARA"
    
    $da= New-Object System.Data.CData.SAPERP.SAPERPDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_.mandt $_.mbrsh
    }
      

Ready to get started?

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

 Download Now

Learn more:

SAP ERP Icon SAP ERP ADO.NET Provider

Straightforward SAP ERP integration. Now accessing SAP RFC's from .NET applications is as easy as querying SQL Server.