Ready to get started?

Learn more about the SAP ERP PowerShell Cmdlets or download a free trial:

Download Now

PowerShell でSAP Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってSAP テーブルにアクセス。

CData Cmdlets Module for SAP は、直感的なSAP データ連携を提供する標準cmdlet です。 本記事では、SAPERP 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.