![]() |
VOOZH | about |
The CData Cmdlets for Paylocity offer live access to Paylocity 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 Paylocity and the CData Cmdlets for MySQL in PowerShell to replicate Paylocity data to a MySQL database.
After obtaining the needed connection properties, accessing Paylocity data in PowerShell and preparing for replication consists of four basic steps.
Set the following to establish a connection to Paylocity:
This property is required for executing Insert and Update statements, and it is not required if the feature is disabled.
Paylocity will decrypt the AES key using RSA decryption.
It is an optional property if the IV value not provided, The driver will generate a key internally.
You must use OAuth to authenticate with Paylocity. OAuth requires the authenticating user to interact with Paylocity using the browser. For more information, refer to the OAuth section in the Help documentation.
The Pay Entry API is completely separate from the rest of the Paylocity API. It uses a separate Client ID and Secret, and must be explicitly requested from Paylocity for access to be granted for an account. The Pay Entry API allows you to automatically submit payroll information for individual employees, and little else. Due to the extremely limited nature of what is offered by the Pay Entry API, we have elected not to give it a separate schema, but it may be enabled via the UsePayEntryAPI connection property.
Please be aware that when setting UsePayEntryAPI to true, you may only use the CreatePayEntryImportBatch & MergePayEntryImportBatchgtable stored procedures, the InputTimeEntry table, and the OAuth stored procedures. Attempts to use other features of the product will result in an error. You must also store your OAuthAccessToken separately, which often means setting a different OAuthSettingsLocation when using this connection property.
Install the module:
Install-Module PaylocityCmdlets
Connect to Paylocity:
$paylocity = Connect-Paylocity -OAuthClientID $OAuthClientID -OAuthClientSecret $OAuthClientSecret -RSAPublicKey $RSAPublicKey -Key $Key -IV $IV -InitiateOAuth $InitiateOAuth
Retrieve the data from a specific resource:
$data = Select-Paylocity -Connection $paylocity -Table "Employee"
You can also use the Invoke-Paylocity cmdlet to execute pure SQL-92 statements:
$data = Invoke-Paylocity -Connection $paylocity -Query 'SELECT * FROM Employee WHERE EmployeeId = @EmployeeId' -Params @{'@EmployeeId'='1234'}
Save a list of the column names from the returned data.
$columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name
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 Paylocity 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 Paylocity resource (Employee) and to exist in the database.
$data | % {
$row = $_
$values = @()
$columns | % {
$col = $_
$values += $row.$($col)
}
Add-MySQL -Connection $mysql -Table "Employee" -Columns $columns -Values $values
}
You have now replicated your Paylocity data to a MySQL database. This gives you freedom to work with Paylocity 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 Paylocity and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:
Select-Paylocity -Connection $paylocity -Table "Employee" | % {
$row = $_
$values = @()
$columns | % {
$col = $_
$values += $row.$($col)
}
Add-MySQL -Connection $mysql -Table "Employee" -Columns $columns -Values $values
}
If you wish to replicate the Paylocity 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-Paylocity 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')}
Download a free trial of the Paylocity Cmdlets to get started:
Download NowLearn more:
👁 Paylocity IconAn easy-to-use set of PowerShell Cmdlets offering real-time access to Paylocity. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.