Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →How to pipe Adobe Commerce Data to CSV in PowerShell
Use standard PowerShell cmdlets to access Adobe Commerce tables.
The CData Cmdlets Module for Adobe Commerce is a standard PowerShell module offering straightforward integration with Adobe Commerce. Below, you will find examples of using our Adobe Commerce Cmdlets with native PowerShell cmdlets.
Creating a Connection to Your Adobe Commerce Data
Adobe Commerce uses the OAuth 1 authentication standard. To connect to the Adobe Commerce REST API, you will need to obtain values for the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties by registering an app with your Adobe Commerce system. See the "Getting Started" section in the help documentation for a guide to obtaining the OAuth values and connecting.
You will also need to provide the URL to your Adobe Commerce system. The URL depends on whether you are using the Adobe Commerce REST API as a customer or administrator.
Customer: To use Adobe Commerce as a customer, make sure you have created a customer account in the Adobe Commerce homepage. To do so, click Account -> Register. You can then set the URL connection property to the endpoint of your Adobe Commerce system.
Administrator: To access Adobe Commerce as an administrator, set CustomAdminPath instead. This value can be obtained in the Advanced settings in the Admin menu, which can be accessed by selecting System -> Configuration -> Advanced -> Admin -> Admin Base URL.
If the Use Custom Admin Path setting on this page is set to YES, the value is inside the Custom Admin Path text box; otherwise, set the CustomAdminPath connection property to the default value, which is "admin".
$conn = Connect-Adobe Commerce -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL" -Url "$Url"
Selecting Data
Follow the steps below to retrieve data from the Products table and pipe the result into to a CSV file:
Select-Adobe Commerce -Connection $conn -Table Products | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myProductsData.csv -NoTypeInformation
You will notice that we piped the results from Select-Adobe Commerce into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.
The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.Deleting Data
The following line deletes any records that match the criteria:
Select-Adobe Commerce -Connection $conn -Table Products -Where "Style = High Tech" | Remove-Adobe Commerce
Inserting and Updating Data
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Adobe Commerce, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MyProductsUpdates.csv | %{ $record = Select-Adobe Commerce -Connection $Adobe Commerce -Table Products -Where ("EntityId = `'"+$_.EntityId+"`'") if($record){ Update-Adobe Commerce -Connection $adobe commerce -Table Products -Columns ("Name","Price") -Values ($_.Name, $_.Price) -Where ("EntityId = `'"+$_.EntityId+"`'") }else{ Add-Adobe Commerce -Connection $adobe commerce -Table Products -Columns ("Name","Price") -Values ($_.Name, $_.Price) } }
As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!