Pipe SAP Data to CSV in PowerShell

Ready to get started?

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

 Download Now

Learn more:

SAP ERP Icon SAP ERP Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to SAP ERP data. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.

Use standard PowerShell cmdlets to access SAP tables.

The CData Cmdlets Module for SAP is a standard PowerShell module offering straightforward integration with SAP. Below, you will find examples of using our SAPERP Cmdlets with native PowerShell cmdlets.

Creating a Connection to Your SAP Data

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.

$conn = Connect-SAPERP  -Host "$Host" -User "$User" -Password "$Password" -Client "$Client" -System Number "$System Number" -ConnectionType "$ConnectionType" -Location "$Location"

Selecting Data

Follow the steps below to retrieve data from the MARA table and pipe the result into to a CSV file:

Select-SAPERP -Connection $conn -Table MARA | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myMARAData.csv -NoTypeInformation

You will notice that we piped the results from Select-SAPERP into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.