PowerShell Scripting to Replicate Oracle Eloqua Reporting Data to MySQL
The CData Cmdlets for Oracle Eloqua Reporting offer live access to Oracle Eloqua Reporting data from within PowerShell. Using PowerShell scripts, you can easily automate regular tasks like data replication. This article will walk through using the CData Cmdlets for Oracle Eloqua Reporting and the CData Cmdlets for MySQL in PowerShell to replicate Oracle Eloqua Reporting data to a MySQL database.
After obtaining the needed connection properties, accessing Oracle Eloqua Reporting data in PowerShell and preparing for replication consists of four basic steps.
Oracle Eloqua Reporting supports the following authentication methods:
- Basic authentication (User and Password)
- OAuth 2.0 code grant flow
- OAuth 2.0 password grant flow
Basic Authentication (User and Password)
To perform authentication with a user and password, specify these properties:
- AuthScheme: Basic.
- Company: The company name associated with your Oracle Eloqua Reporting account.
- User: Your login account name.
- Password: Your login password.
OAuth Authentication (Code Grant Flow)
To authenticate with the OAuth code grant flow, you must set AuthScheme to OAuth and create a custom OAuth application. For information about how to create a custom OAuth application, see the Help documentation.
Then set the following properties:
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
- OAuthClientId: The client Id assigned when you registered your application.
- OAuthClientSecret: The client secret that was assigned when you registered your application.
- CallbackURL: The redirect URI that was defined when you registered your application.
When you connect, the driver opens Oracle Eloqua Reporting's OAuth endpoint in your default browser. Log in and grant permissions to the application. When the access token expires, the driver refreshes it automatically.
OAuth Authentication (Password Grant Flow)
With the OAuth password grant flow, you can use your OAuth application's credentials alongside your user credentials to authenticate without the need to grant permission manually via a browser prompt. You must create an OAuth app (see the Help documentation) to use this authentication method.
Set the following properties:
- AuthScheme: OAuthPassword
- Company: The company's unique identifier.
- User: Your login account name.
- Password: Your login password.
- OAuthClientId: The client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The client secret assigned when you registered your custom OAuth application.
Collecting Oracle Eloqua Reporting Data
-
Install the module:
Install-Module OracleEloquaReportingCmdlets
-
Connect to Oracle Eloqua Reporting:
$oracleeloquareporting = Connect-OracleEloquaReporting -AuthScheme $AuthScheme -User $User -Password $Password -Company $Company
-
Retrieve the data from a specific resource:
$data = Select-OracleEloquaReporting -Connection $oracleeloquareporting -Table ""
You can also use the Invoke-OracleEloquaReporting cmdlet to execute pure SQL-92 statements:
$data = Invoke-OracleEloquaReporting -Connection $oracleeloquareporting -Query 'SELECT * FROM WHERE = @' -Params @{'@'=''} -
Save a list of the column names from the returned data.
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name
Inserting Oracle Eloqua Reporting Data into the MySQL Database
With the data and column names collected, you are ready to replicate the data into a MySQL database.
-
Install the module:
Install-Module MySQLCmdlets
-
Connect to MySQL, using the server address and port of the MySQL server, valid user credentials, and a specific database with the table in which the data will be replicated:
$mysql = Connect-MySQL -User $User -Password $Password -Database $Database -Server $Server -Port $Port
-
Loop through the Oracle Eloqua Reporting data, store the values, and use the Add-MySQL cmdlet to insert the data into the MySQL database, one row at a time. In this example, the table will need to have the same name as the Oracle Eloqua Reporting resource () and to exist in the database.
$data | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "" -Columns $columns -Values $values }
You have now replicated your Oracle Eloqua Reporting data to a MySQL database. This gives you freedom to work with Oracle Eloqua Reporting data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.
Notes
-
Once you have connected to Oracle Eloqua Reporting and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:
Select-OracleEloquaReporting -Connection $oracleeloquareporting -Table "" | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "" -Columns $columns -Values $values } -
If you wish to replicate the Oracle Eloqua Reporting data to another database using another PowerShell module, you will want to exclude the Columns, Connection, and Table columns from the data returned by the Select-OracleEloquaReporting cmdlet since those columns are used to help pipe data from one CData cmdlet to another:
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name | ? {$_ -NotIn @('Columns','Connection','Table')}