Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →PowerShell Scripting to Replicate PingOne Data to MySQL
Write a simple PowerShell script to replicate PingOne data to a MySQL database.
The CData Cmdlets for PingOne offer live access to PingOne 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 PingOne and the CData Cmdlets for MySQL in PowerShell to replicate PingOne data to a MySQL database.
After obtaining the needed connection properties, accessing PingOne data in PowerShell and preparing for replication consists of four basic steps.
To connect to PingOne, configure these properties:
- Region: The region where the data for your PingOne organization is being hosted.
- AuthScheme: The type of authentication to use when connecting to PingOne.
- Either WorkerAppEnvironmentId (required when using the default PingOne domain) or AuthorizationServerURL, configured as described below.
Configuring WorkerAppEnvironmentId
WorkerAppEnvironmentId is the ID of the PingOne environment in which your Worker application resides. This parameter is used only when the environment is using the default PingOne domain (auth.pingone). It is configured after you have created the custom OAuth application you will use to authenticate to PingOne, as described in Creating a Custom OAuth Application in the Help documentation.
First, find the value for this property:
- From the home page of your PingOne organization, move to the navigation sidebar and click Environments.
- Find the environment in which you have created your custom OAuth/Worker application (usually Administrators), and click Manage Environment. The environment's home page displays.
- In the environment's home page navigation sidebar, click Applications.
- Find your OAuth or Worker application details in the list.
-
Copy the value in the Environment ID field.
It should look similar to:
WorkerAppEnvironmentId='11e96fc7-aa4d-4a60-8196-9acf91424eca'
Now set WorkerAppEnvironmentId to the value of the Environment ID field.
Configuring AuthorizationServerURL
AuthorizationServerURL is the base URL of the PingOne authorization server for the environment where your application is located. This property is only used when you have set up a custom domain for the environment, as described in the PingOne platform API documentation. See Custom Domains.
Authenticating to PingOne with OAuth
PingOne supports both OAuth and OAuthClient authentication. In addition to performing the configuration steps described above, there are two more steps to complete to support OAuth or OAuthCliet authentication:
- Create and configure a custom OAuth application, as described in Creating a Custom OAuth Application in the Help documentation.
- To ensure that the driver can access the entities in Data Model, confirm that you have configured the correct roles for the admin user/worker application you will be using, as described in Administrator Roles in the Help documentation.
- Set the appropriate properties for the authscheme and authflow of your choice, as described in the following subsections.
OAuth (Authorization Code grant)
Set AuthScheme to OAuth.
Desktop Applications
Get and Refresh the OAuth Access Token
After setting the following, you are ready to connect:
- InitiateOAuth: GETANDREFRESH. To avoid the need to repeat the OAuth exchange and manually setting the OAuthAccessToken each time you connect, use InitiateOAuth.
- OAuthClientId: The Client ID you obtained when you created your custom OAuth application.
- OAuthClientSecret: The Client Secret you obtained when you created your custom OAuth application.
- CallbackURL: The redirect URI you defined when you registered your custom OAuth application. For example: https://localhost:3333
When you connect, the driver opens PingOne's OAuth endpoint in your default browser. Log in and grant permissions to the application. The driver then completes the OAuth process:
- The driver obtains an access token from PingOne and uses it to request data.
- The OAuth values are saved in the location specified in OAuthSettingsLocation, to be persisted across connections.
The driver refreshes the access token automatically when it expires.
For other OAuth methods, including Web Applications, Headless Machines, or Client Credentials Grant, refer to the Help documentation.
Collecting PingOne Data
-
Install the module:
Install-Module PingOneCmdlets
-
Connect to PingOne:
$pingone = Connect-PingOne -AuthScheme $AuthScheme -WorkerAppEnvironmentId $WorkerAppEnvironmentId -Region $Region -OAuthClientId $OAuthClientId -OAuthClientSecret $OAuthClientSecret
-
Retrieve the data from a specific resource:
$data = Select-PingOne -Connection $pingone -Table "[CData].[Administrators].Users"
You can also use the Invoke-PingOne cmdlet to execute pure SQL-92 statements:
$data = Invoke-PingOne -Connection $pingone -Query 'SELECT * FROM [CData].[Administrators].Users WHERE EmployeeType = @EmployeeType' -Params @{'@EmployeeType'='Contractor'} -
Save a list of the column names from the returned data.
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name
Inserting PingOne 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 PingOne 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 PingOne resource ([CData].[Administrators].Users) and to exist in the database.
$data | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "[CData].[Administrators].Users" -Columns $columns -Values $values }
You have now replicated your PingOne data to a MySQL database. This gives you freedom to work with PingOne 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 PingOne and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:
Select-PingOne -Connection $pingone -Table "[CData].[Administrators].Users" | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "[CData].[Administrators].Users" -Columns $columns -Values $values } -
If you wish to replicate the PingOne 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-PingOne 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')}