Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate SAP ByDesign Integration Tasks from PowerShell
Are you in search of a quick and easy way to access SAP ByDesign data from PowerShell? This article demonstrates how to utilize the SAP ByDesign Cmdlets for tasks like connecting to SAP ByDesign data, automating operations, downloading data, and more.
The CData Cmdlets for SAP ByDesign 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 ByDesign.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to SAP ByDesign, but also an SQL interface; this tutorial shows how to use both to retrieve SAP ByDesign data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP ByDesign. To access SAP ByDesign data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP ByDesign.
Once you have acquired the necessary connection properties, accessing SAP ByDesign data in PowerShell can be enabled in three steps.
Set the following connection properties to connect to SAP ByDesign.
- Url: Set this to the Url of your SAP ByDesign site. For example, https://test.sapbydesign.com
- User: Set this to the username of your account.
- Password: Set this to the password of your account.
- CustomService or AnalyticsService: Only one of these must be specified. If you have a custom service you want to retrieve data from, specify CustomService. If you want to retrieve the reports of a analytical service, specify AnalyticsService.
If neither is specified, 'cc_home_analytics.svc' will used as a default for the AnalyticsService property. If you are not sure what service to specify, you can always query the Services view to list available services.
PowerShell
-
Install the module:
Install-Module SAPByDesignCmdlets
-
Connect:
$sapbydesign = Connect-SAPByDesign -URL "$URL" -User "$User" -Password "$Password" -CustomService "$CustomService"
-
Search for and retrieve data:
$productcategoryid = "1234567" $[inventory balance] = Select-SAPByDesign -Connection $sapbydesign -Table "[Inventory Balance]" -Where "ProductCategoryID = `'$ProductCategoryID`'" $[inventory balance]
You can also use the Invoke-SAPByDesign cmdlet to execute SQL commands:
$[inventory balance] = Invoke-SAPByDesign -Connection $sapbydesign -Query 'SELECT * FROM [Inventory Balance] WHERE ProductCategoryID = @ProductCategoryID' -Params @{'@ProductCategoryID'='1234567'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP ByDesign\lib\System.Data.CData.SAPByDesign.dll")
-
Connect to SAP ByDesign:
$conn= New-Object System.Data.CData.SAPByDesign.SAPByDesignConnection("URL=https://my999999.sapbydesign.com;User=username;Password=password;CustomService=servicename;") $conn.Open()
-
Instantiate the SAPByDesignDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ID, ProductCategoryID from [Inventory Balance]" $da= New-Object System.Data.CData.SAPByDesign.SAPByDesignDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.productcategoryid }