Replicate Adobe Target Data from PowerShell



Write a quick PowerShell script to query Adobe Target data. Use connectivity to the live data to replicate Adobe Target data to SQL Server.



The CData ODBC Driver for Adobe Target enables out-of-the-box integration with Microsoft's built-in support for ODBC. The ODBC driver instantly integrates connectivity to the real Adobe Target data with PowerShell.

You can use the .NET Framework Provider for ODBC built into PowerShell to quickly automate integration tasks like replicating Adobe Target data to other databases. This article shows how to replicate Adobe Target data to SQL Server in 5 lines of code.

You can also write PowerShell code to download Adobe Target data. See the examples below.

Create an ODBC Data Source for Adobe Target

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

To connect to Adobe Target, you must provide the Tenant property along with OAuth connection properties mentioned below. Note that while other connection properties can influence processing behavior, they do not affect the ability to connect.

To determine your Tenant name:

  1. Log in to Adobe Experience. The URL will look similar to: "https://experience.adobe.com/#/@mycompanyname/preferences/general-section".
  2. Extract the value after the "/#/@". In this example, it is "mycompanyname".
  3. Set the Tenant connection property to that value.

User Accounts (OAuth)

You must set AuthScheme to OAuthClient for all user account flows.

Note: Adobe authentication via OAuth requires updating your token every two weeks.

All Applications

CData provides an embedded OAuth application that simplifies OAuth authentication. Alternatively, you can create a custom OAuth application. Review Creating a Custom OAuth App in the Help documentation for more information.

Obtaining the OAuth Access Token

Set the following properties to connect:

  • InitiateOAuth: Set to GETANDREFRESH to automatically perform the OAuth exchange and refresh the OAuthAccessToken as needed.
  • OAuthClientId : Set to the client Id assigned when you registered your app.
  • OAuthClientSecret : Set to the client secret assigned when you registered your app.
  • CallbackURL : Set to the redirect URI defined when you registered your app. For example: https://localhost:3333

With these settings, the provider obtains an access token from Adobe Target, which it uses to request data. The OAuth values are stored in the location specified by OAuthSettingsLocation, ensuring they persist across connections.

Connect to Adobe Target

The code below shows how to use the DSN to initialize the connection to Adobe Target data in PowerShell:

$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "DSN=CData AdobeTarget Source x64"

Back Up Adobe Target Data to SQL Server

After you enable caching, you can use the code below to replicate data to SQL Server.

Set the following connection properties to configure the caching database:

  • CacheProvider: The name of the ADO.NET provider. This can be found in the Machine.config for your version of .NET. For example, to configure SQL Server, enter System.Data.SqlClient.

  • CacheConnection: The connection string of properties required to connect to the database. Below is an example for SQL Server:

    Server=localhost;Database=RSB;User Id=sqltest;Password=sqltest;

The SQL query in the example can be used to refresh the entire cached table, including its schema. Any already existing cache is deleted.

$conn.Open()
# Create and execute the SQL Query
$SQL = "CACHE DROP EXISTING SELECT * FROM " + $Activities
$cmd = New-Object System.Data.Odbc.OdbcCommand($sql,$conn)
$count = $cmd.ExecuteNonQuery()
$conn.Close()

The driver gives you complete control over the caching functionality. See the help documentation for more caching commands and usage examples. See the help documentation for steps to replicate to other databases.

Other Operations

To retrieve Adobe Target data in PowerShell, call the Fill method of the OdbcDataAdapter method. To execute data manipulation commands, initialize the OdbcCommand object and then call ExecuteNonQuery. Below are some more examples commands to Adobe Target through the .NET Framework Provider for ODBC:

Retrieve Adobe Target Data

$sql="SELECT Id, Name from Activities"
 
$da= New-Object System.Data.Odbc.OdbcDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt) 
 
$dt.Rows | foreach {
  $dt.Columns | foreach ($col in dt{
    Write-Host $1[$_]
  }
}

Ready to get started?

Download a free trial of the Adobe Target ODBC Driver to get started:

 Download Now

Learn more:

Adobe Target Icon Adobe Target ODBC Driver

The Adobe Target ODBC Driver is a powerful tool that allows you to connect with live data from live Adobe Target, directly from any applications that support ODBC connectivity.

Read, write, and update online sheets through a standard ODBC interface.