Ready to get started?

Download a free trial of the SAP Hybris Data Provider to get started:

 Download Now

Learn more:

SAP Hybris C4C Icon SAP Hybris ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with SAP Hybris C4C data including Leads, Contacts, Opportunities, Accounts, and more!

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

  1. Install the module:

    Install-Module SAPHybrisC4CCmdlets
  2. Connect:

    $saphybrisc4c = Connect-SAPHybrisC4C -User "$User" -Password "$Password"
  3. 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

  1. 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")
  2. Connect to SAP Hybris C4C:

    $conn= New-Object System.Data.CData.SAPHybrisC4C.SAPHybrisC4CConnection("User=user;Password=password;") $conn.Open()
  3. 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()