We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Automate SAP Hybris C4C Integration Tasks from PowerShell
Are you in search of a quick and easy way to access SAP Hybris C4C data from PowerShell? This article demonstrates how to utilize the SAP Hybris C4C Cmdlets for tasks like connecting to SAP Hybris C4C data, automating operations, downloading data, and more.
The CData Cmdlets for SAP Hybris C4C are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SAP Hybris C4C.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to SAP Hybris C4C, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SAP Hybris C4C data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP Hybris C4C. To access SAP Hybris C4C data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP Hybris C4C.
Once you have acquired the necessary connection properties, accessing SAP Hybris C4C data in PowerShell can be enabled in three steps.
SAP Hybris Cloud for Customer uses basic authentication. Set the User and Password to your login credentials.
PowerShell
-
Install the module:
Install-Module SAPHybrisC4CCmdlets
-
Connect:
$saphybrisc4c = Connect-SAPHybrisC4C -User "$User" -Password "$Password"
-
Search for and retrieve data:
$accountname = "MyAccount" $accountcollection = Select-SAPHybrisC4C -Connection $saphybrisc4c -Table "AccountCollection" -Where "AccountName = `'$AccountName`'" $accountcollection
You can also use the Invoke-SAPHybrisC4C cmdlet to execute SQL commands:
$accountcollection = Invoke-SAPHybrisC4C -Connection $saphybrisc4c -Query 'SELECT * FROM AccountCollection WHERE AccountName = @AccountName' -Params @{'@AccountName'='MyAccount'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP Hybris C4C\lib\System.Data.CData.SAPHybrisC4C.dll")
-
Connect to SAP Hybris C4C:
$conn= New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CConnection("User=user;Password=password;") $conn.Open()
-
Instantiate the SAPHybrisC4CDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ObjectID, AccountName from AccountCollection" $da= New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.objectid $_.accountname }
Update SAP Hybris C4C Data
PowerShell
Update-SAPHybrisC4C -Connection $SAPHybrisC4C -Columns @('ObjectID','AccountName') -Values @('MyObjectID', 'MyAccountName') -Table AccountCollection -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CCommand("UPDATE AccountCollection SET AccountName='MyAccount' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert SAP Hybris C4C Data
PowerShell
Add-SAPHybrisC4C -Connection $SAPHybrisC4C -Table AccountCollection -Columns @("ObjectID", "AccountName") -Values @("MyObjectID", "MyAccountName")
ADO.NET
$cmd = New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CCommand("INSERT INTO AccountCollection (AccountName) VALUES (@myAccountName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CParameter("@myAccountName","MyAccount")))
$cmd.ExecuteNonQuery()
Delete SAP Hybris C4C Data
PowerShell
Remove-SAPHybrisC4C -Connection $SAPHybrisC4C -Table "AccountCollection" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CCommand("DELETE FROM AccountCollection WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject