Ready to get started?

Download a free trial of the SAP SuccessFactors Cmdlets to get started:

 Download Now

Learn more:

SAP SuccessFactors Icon SAP SuccessFactors Data Cmdlets

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

PowerShell Scripting to Replicate SAP SuccessFactors Data to MySQL



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

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

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

You can authenticate to SAP Success Factors using Basic authentication or OAuth with SAML assertion.

Basic Authentication

You must provide values for the following properties to successfully authenticate to SAP Success Factors. Note that the provider will reuse the session opened by SAP Success Factors using cookies. Which means that your credentials will be used only on the first request to open the session. After that, cookies returned from SAP Success Factors will be used for authentication.

  • Url: set this to the URL of the server hosting Success Factors. Some of the servers are listed in the SAP support documentation (external link).
  • User: set this to the username of your account.
  • Password: set this to the password of your account.
  • CompanyId: set this to the unique identifier of your company.

OAuth Authentication

You must provide values for the following properties, which will be used to get the access token.

  • Url: set this to the URL of the server hosting Success Factors. Some of the servers are listed in the SAP support documentation (external link).
  • User: set this to the username of your account.
  • CompanyId: set this to the unique identifier of your company.
  • OAuthClientId: set this to the API Key that was generated in API Center.
  • OAuthClientSecret: the X.509 private key used to sign SAML assertion. The private key can be found in the certificate you downloaded in Registering your OAuth Client Application.
  • InitiateOAuth: set this to GETANDREFRESH.

Collecting SAP SuccessFactors Data

  1. Install the module:

    Install-Module SAPSuccessFactorsCmdlets
  2. Connect to SAP SuccessFactors:

    $sapsuccessfactors = Connect-SAPSuccessFactors -User $User -Password $Password -CompanyId $CompanyId -Url $Url
  3. Retrieve the data from a specific resource:

    $data = Select-SAPSuccessFactors -Connection $sapsuccessfactors -Table "ExtAddressInfo"

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

    $data = Invoke-SAPSuccessFactors -Connection $sapsuccessfactors -Query 'SELECT * FROM ExtAddressInfo WHERE city = @city' -Params @{'@city'='Springfield'}
  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 SuccessFactors 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 SuccessFactors 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 SuccessFactors resource (ExtAddressInfo) and to exist in the database.

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

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

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