Ready to get started?

Learn more about the CData ADO.NET Provider for SAP Fieldglass or download a free trial:

Download Now

Automate SAP Fieldglass Integration Tasks from PowerShell

Are you looking for a quick and easy way to access SAP Fieldglass data from PowerShell? We show how to use the Cmdlets for SAP Fieldglass and the CData ADO.NET Provider for SAP Fieldglass to connect to SAP Fieldglass data and synchronize, automate, download, and more.

The CData Cmdlets for SAP Fieldglass 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 Fieldglass.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the SAP Fieldglass API, but also an SQL interface; this tutorial shows how to use both to retrieve SAP Fieldglass data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP Fieldglass. To access SAP Fieldglass data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP Fieldglass.

After obtaining the needed connection properties, accessing SAP Fieldglass data in PowerShell consists of three basic steps.

To authenticate, you will need to specify the Username, Password, APIKey, and EnvironmentURL connection properties.

To obtain an APIKey, log in to the SAP API Business Hub and click on Get API Key.

PowerShell

  1. Install the module:

    Install-Module SAPFieldglassCmdlets
  2. Connect:

    $sapfieldglass = Connect-SAPFieldglass -EnvironmentURL "$EnvironmentURL" -Username "$Username" -Password "$Password" -APIKey "$APIKey"
  3. Search for and retrieve data:

    $company = "CData" $audittrails = Select-SAPFieldglass -Connection $sapfieldglass -Table "AuditTrails" -Where "Company = `'$Company`'" $audittrails

    You can also use the Invoke-SAPFieldglass cmdlet to execute SQL commands:

    $audittrails = Invoke-SAPFieldglass -Connection $sapfieldglass -Query 'SELECT * FROM AuditTrails WHERE Company = @Company' -Params @{'@Company'='CData'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.SAPFieldglass.SAPFieldglassConnection("EnvironmentURL='https://myinstance.com';Username=myuser;Password=mypassword;APIKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SAPFieldglassDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, Category from AuditTrails" $da= New-Object System.Data.CData.SAPFieldglass.SAPFieldglassDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.category }