PowerShell Scripting to Replicate SAP BusinessObjects BI Data to MySQL

Ready to get started?

Download for a free trial:

Download Now

Learn more:

SAP BusinessObjects BI Data Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to SAP BusinessObjects BI. The Cmdlets allow users to easily connect to live data - just like working with SQL server.



Write a simple PowerShell script to replicate SAP BusinessObjects BI data to a MySQL database.

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

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

To connect to your SAP Business Objects BI instance, you must set the following connection properties:

  • Url: set this to the rest API URL. After logging into the Central Management Console, choose 'Applications' from the combo box. Double-click on 'RESTful Web Service' and you'll see the access URL. By default it is, http://{Server-Name}:6405/biprws.
  • User: set this to the username of your instance.
  • Password: set this to the password of your instance.

Collecting SAP BusinessObjects BI Data

  1. Install the module:

    Install-Module SAPBusinessObjectsBICmdlets
  2. Connect to SAP BusinessObjects BI:

    $sapbusinessobjectsbi = Connect-SAPBusinessObjectsBI -User $User -Password $Password -Url $Url
  3. Retrieve the data from a specific resource:

    $data = Select-SAPBusinessObjectsBI -Connection $sapbusinessobjectsbi -Table "MyCustomReport"

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

    $data = Invoke-SAPBusinessObjectsBI -Connection $sapbusinessobjectsbi -Query 'SELECT * FROM MyCustomReport WHERE State = @State' -Params @{'@State'='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 SAP BusinessObjects BI 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 SAP BusinessObjects BI 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 SAP BusinessObjects BI resource (MyCustomReport) and to exist in the database.

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

You have now replicated your SAP BusinessObjects BI data to a MySQL database. This gives you freedom to work with SAP BusinessObjects BI 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 SAP BusinessObjects BI and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:

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