![]() |
VOOZH | about |
The CData Cmdlets for Paylocity are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Paylocity.
The Cmdlets are not only a PowerShell interface to Paylocity, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Paylocity data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Paylocity. To access Paylocity data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Paylocity.
Once you have acquired the necessary connection properties, accessing Paylocity data in PowerShell can be enabled in three 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:
$paylocity = Connect-Paylocity -OAuthClientID "$OAuthClientID" -OAuthClientSecret "$OAuthClientSecret" -RSAPublicKey "$RSAPublicKey" -Key "$Key" -IV "$IV" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$employeeid = "1234" $employee = Select-Paylocity -Connection $paylocity -Table "Employee" -Where "EmployeeId = `'$EmployeeId`'" $employee
You can also use the Invoke-Paylocity cmdlet to execute SQL commands:
$employee = Invoke-Paylocity -Connection $paylocity -Query 'SELECT * FROM Employee WHERE EmployeeId = @EmployeeId' -Params @{'@EmployeeId'='1234'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Paylocity\lib\System.Data.CData.Paylocity.dll")
Connect to Paylocity:
$conn= New-Object System.Data.CData.Paylocity.PaylocityConnection("OAuthClientID=YourClientId;OAuthClientSecret=YourClientSecret;RSAPublicKey=YourRSAPubKey;Key=YourKey;IV=YourIV;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the PaylocityDataAdapter, execute an SQL query, and output the results:
$sql="SELECT FirstName, LastName from Employee"
$da= New-Object System.Data.CData.Paylocity.PaylocityDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.firstname $_.lastname
}
Update-Paylocity -Connection $Paylocity -Columns @('FirstName','LastName') -Values @('MyFirstName', 'MyLastName') -Table Employee -Id "MyId"
$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("UPDATE Employee SET EmployeeId='1234' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Paylocity.PaylocityParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Paylocity -Connection $Paylocity -Table Employee -Columns @("FirstName", "LastName") -Values @("MyFirstName", "MyLastName")
$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("INSERT INTO Employee (EmployeeId) VALUES (@myEmployeeId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Paylocity.PaylocityParameter("@myEmployeeId","1234")))
$cmd.ExecuteNonQuery()
Remove-Paylocity -Connection $Paylocity -Table "Employee" -Id "MyId"
$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("DELETE FROM Employee WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Paylocity.PaylocityParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Paylocity Data Provider to get started:
Download NowLearn more:
👁 Paylocity IconRapidly create and deploy powerful .NET applications that integrate with Paylocity.