SapConnect

The SapConnect object is of type ScriptBlock and can be used with Connect-ERP to work with SAP systems.

The $sapConnect variable is based on the SapConnect implementation from the .NET library.

Syntax

1
$sapConnect

Remarks

The $sapConnect variable is available globally in every powershell session where the powerGate Module is imported.
It only supports connecting to the services from a single SAP system, by retrieving the X-CSRF-Token and cookie just once.

Examples

Connecting to a SAP service with CSRF protection

1
2
Connect-ERP -Service "http://sap.coolorange.com" -User "EX_DEMO" -Password "secret" -OnConnect
$global:sapConnect

Connecting multiple SAP systems with different CSRF-Token expiration intervals:

1
2
3
4
5
6
7
8
9
$sapConnect_System2 = {
param($settings)
        # tokens expire every 24h on this system
        $reconnectInterval = 86400 ‬* 1000
        ([Action[powerGate.Erp.Client.ErpClientSettings]](New-Object powerGate.Erp.Client.SapConnect($reconnectInterval))).Invoke($settings)
}

Connect-ERP "http://sap.coolorange.com/CATALOGSERVICE" -OnConnect $Global:sapConnect
Connect-ERP "http://sap.some_other_company.com/CATALOGSERVICE" -OnConnect $sapConnect_System2

Customization

In case the default implementation does not fit your needs (Download Example) the PowerShell module and extract it to your projects location:

1
.\Modules\connections_sap.psm1

Freely customize the module to your needs!
To make use of the module in your current PowerShell environment it has to be imported:

1
Import-Module ".\Modules\connections_sap.psm1"

In order to use the customized SAP Connect for the authentication with powerGate, use the variable $extendedSapConnect:

1
$connected = Connect-ERP "https://sap.coolorange.com/CATALOGSERVICE" -OnConnect $global:extendedSapConnect

Attention

If you are setting $settings.OnCreateMessageHandler then the $settings.OnApplyClientHandler will not be called anymore and the $extendedSapConnect will not work anymore. Therefore be sure to invoke it afterwards with the returned handler:

1
2
3
4
5
6
7
$global:erpSettings = $settings
$settings.OnCreateMessageHandler = {
        $customHandler = New-Object Your.Custom.Handler
        # Your other custom code
        $erpSetting.OnApplyClientHandler.Invoke($customHandler)
        return $customHandler
}