PowerShell Scripting to Replicate Zuora Data to MySQL

Ready to get started?

Download a free trial of the Zuora Cmdlets to get started:

 Download Now

Learn more:

Zuora Icon Zuora Data Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to Zuora. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.

Write a simple PowerShell script to replicate Zuora data to a MySQL database.

The CData Cmdlets for Zuora offer live access to Zuora 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 Zuora and the CData Cmdlets for MySQL in PowerShell to replicate Zuora data to a MySQL database.

After obtaining the needed connection properties, accessing Zuora data in PowerShell and preparing for replication consists of four basic steps.

Zuora uses the OAuth standard to authenticate users. See the online Help documentation for a full OAuth authentication guide.

Configuring Tenant property

In order to create a valid connection with the provider you need to choose one of the Tenant values (USProduction by default) which matches your account configuration. The following is a list with the available options:

  • USProduction: Requests sent to https://rest.zuora.com.
  • USAPISandbox: Requests sent to https://rest.apisandbox.zuora.com"
  • USPerformanceTest: Requests sent to https://rest.pt1.zuora.com"
  • EUProduction: Requests sent to https://rest.eu.zuora.com"
  • EUSandbox: Requests sent to https://rest.sandbox.eu.zuora.com"

Selecting a Zuora Service

Two Zuora services are available: Data Query and AQuA API. By default ZuoraService is set to AQuADataExport.


The Data Query feature enables you to export data from your Zuora tenant by performing asynchronous, read-only SQL queries. We recommend to use this service for quick lightweight SQL queries.

  • The maximum number of input records per table after filters have been applied: 1,000,000
  • The maximum number of output records: 100,000
  • The maximum number of simultaneous queries submitted for execution per tenant: 5
  • The maximum number of queued queries submitted for execution after reaching the limitation of simultaneous queries per tenant: 10
  • The maximum processing time for each query in hours: 1
  • The maximum size of memory allocated to each query in GB: 2
  • The maximum number of indices when using Index Join, in other words, the maximum number of records being returned by the left table based on the unique value used in the WHERE clause when using Index Join: 20,000


AQuA API export is designed to export all the records for all the objects ( tables ). AQuA query jobs have the following limitations:

  • If a query in an AQuA job is executed longer than 8 hours, this job will be killed automatically.
  • The killed AQuA job can be retried three times before returned as failed.

Collecting Zuora Data

  1. Install the module:

    Install-Module ZuoraCmdlets
  2. Connect to Zuora:

    $zuora = Connect-Zuora -OAuthClientID $OAuthClientID -OAuthClientSecret $OAuthClientSecret -Tenant $Tenant -ZuoraService $ZuoraService
  3. Retrieve the data from a specific resource:

    $data = Select-Zuora -Connection $zuora -Table "Invoices"

    You can also use the Invoke-Zuora cmdlet to execute pure SQL-92 statements:

    $data = Invoke-Zuora -Connection $zuora -Query 'SELECT * FROM Invoices WHERE BillingState = @BillingState' -Params @{'@BillingState'='CA'}
  4. Save a list of the column names from the returned data.

    $columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name

Inserting Zuora Data into the MySQL Database

With the data and column names collected, you are ready to replicate the data into a MySQL database.

  1. Install the module:

    Install-Module MySQLCmdlets
  2. 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
  3. Loop through the Zuora 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 Zuora resource (Invoices) and to exist in the database.

    $data | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Invoices" -Columns $columns -Values $values }

You have now replicated your Zuora data to a MySQL database. This gives you freedom to work with Zuora data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.


  • Once you have connected to Zuora and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:

    Select-Zuora -Connection $zuora -Table "Invoices" | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Invoices" -Columns $columns -Values $values }
  • If you wish to replicate the Zuora 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-Zuora 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')}