Establishing a Connection
With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our AdobeExperienceManager Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.
Connecting to Adobe Experience Manager JCR Repository
This connection allows you to access content stored in an Adobe Experience Manager (AEM) JCR repository using WebDAV. The JCR (Java Content Repository) is the underlying storage system used by AEM to manage content nodes, properties, and metadata. You can connect to both local AEM instances and cloud-based AEM environments.
- Set the URL to the WebDAV-enabled JCR server.
- Local development: http://localhost:4502/crx/server
- AEM as a Cloud Service: https://XXXX-pXXXX-eXXXX.adobeaemcloud.com/crx/server
- Depending on the AuthScheme used:
Once the connection is configured, you can query JCR nodes and properties exposed through the WebDAV endpoint using standard SQL queries. Ensure that the configured user has sufficient permissions to access the required content paths in the AEM repository.
Creating a Connection Object
You can then use the Connect-AdobeExperienceManager cmdlet to create a connection object that can be passed to other cmdlets:
$conn = Connect-AdobeExperienceManager -URL 'http://localhost:4502/crx/server' -User 'admin' -Password 'admin'
Retrieving Data
The Select-AdobeExperienceManager cmdlet provides a native PowerShell interface for retrieving data:
$results = Select-AdobeExperienceManager -Connection $conn -Table "SampleTable_1" -Columns @("Id, Column1") -Where "Column2='Bob'"
The Invoke-AdobeExperienceManager cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.
Piping Cmdlet Output
The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:
Select-AdobeExperienceManager -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySampleTable_1Data.csv -NoTypeInformation
You will notice that we piped the results from Select-AdobeExperienceManager 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 object in the result set, and we do not necessarily want that information in our CSV file.
However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:
PS C:\> $conn = Connect-AdobeExperienceManager -URL 'http://localhost:4502/crx/server' -User 'admin' -Password 'admin'
PS C:\> $row = Select-AdobeExperienceManager -Connection $conn -Table "SampleTable_1" -Columns (Id, Column1) -Where "Column2 = 'Bob'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
"Connection": {
},
"Table": "SampleTable_1",
"Columns": [
],
"Id": "MyId",
"Column1": "MyColumn1"
}
Modifying Data
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Adobe Experience Manager, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MySampleTable_1Updates.csv | %{
$record = Select-AdobeExperienceManager -Connection $conn -Table SampleTable_1 -Where ("Id = `'"+$_.Id+"`'")
if($record){
Update-AdobeExperienceManager -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1) -Where "Id = `'$_.Id`'"
}else{
Add-AdobeExperienceManager -Connection $conn -Table SampleTable_1 -Columns @("Id","Column1") -Values @($_.Id, $_.Column1)
}
}