接続の確立
CData Cmdlets ユーザーは、データモジュールをインストールし、接続プロパティを設定してスクリプトを開始できます。このセクションでは、CSV インポートおよびエクスポートcmdlet などのネイティブPowerShell cmdlet でAdobeExperienceManager 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.
接続オブジェクトの作成
Connect-AdobeExperienceManager cmdlet を使って、別のcmdlet に渡すことができる接続オブジェクトを作成します。
$conn = Connect-AdobeExperienceManager -URL 'http://localhost:4502/crx/server' -User 'admin' -Password 'admin'
データの取得
Select-AdobeExperienceManager cmdlet はデータを取得するためのネイティブなPowerShell インターフェースを提供します。
$results = Select-AdobeExperienceManager -Connection $conn -Table "SampleTable_1" -Columns @("Id, Column1") -Where "Column2='Bob'"
Invoke-AdobeExperienceManager cmdlet はSQL インターフェースを提供します。このcmdlet を使うと、Query パラメータを介してSQL クエリを実行できます。
cmdlet 出力のパイプ処理
cmdlet は行オブジェクトをパイプラインに一度に一行ずつ返します。以下は、結果をCSV ファイルにエクスポートします。
Select-AdobeExperienceManager -Connection $conn -Table SampleTable_1 -Where "Column2 = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySampleTable_1Data.csv -NoTypeInformation
Select-AdobeExperienceManager からの結果をSelect-Object cmdlet にパイプして、Export-CSV cmdlet にパイプする前にいくつかのプロパティを実行していることがわかるでしょう。これをする理由は、CData Cmdlets は接続、テーブル、およびカラムの情報を結果セットの各行オブジェクトに追加しますが、必ずしもその情報がCSV ファイルに必要ではないからです。
ただし、これによってcmdlet の出力を別のcmdlet にパイプすることが容易になります。以下に、結果セットを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"
}
データの変更
cmdlet はデータクレンジング同様、データの変換を容易にします。次の例は、レコードがすでに存在するかどうか、挿入する前に更新が必要かどうかをチェックしてから、CSV ファイルのデータをAdobe Experience Manager にロードします。
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)
}
}