Automate Paylocity Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Paylocity ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Paylocity.



Are you looking for a quick and easy way to access Paylocity data from PowerShell? We show how to use the Cmdlets for Paylocity and the CData ADO.NET Provider for Paylocity to connect to Paylocity data and synchronize, automate, download, and more.

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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Paylocity API, 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.

After obtaining the needed connection properties, accessing Paylocity data in PowerShell consists of three basic steps.

Set the following to establish a connection to Paylocity:

  • RSAPublicKey: Set this to the RSA Key associated with your Paylocity, if the RSA Encryption is enabled in the Paylocity account.

    This property is required for executing Insert and Update statements, and it is not required if the feature is disabled.

  • UseSandbox: Set to true if you are using sandbox account.
  • CustomFieldsCategory: Set this to the Customfields category. This is required when IncludeCustomFields is set to true. The default value for this property is PayrollAndHR.
  • Key: The AES symmetric key(base 64 encoded) encrypted with the Paylocity Public Key. It is the key used to encrypt the content.

    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.

  • IV: The AES IV (base 64 encoded) used when encrypting the content. It is an optional property if the Key value not provided, The driver will generate an IV internally.

Connect Using OAuth Authentication

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

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.

PowerShell

  1. Install the module:

    Install-Module PaylocityCmdlets
  2. Connect:

    $paylocity = Connect-Paylocity -OAuthClientID "$OAuthClientID" -OAuthClientSecret "$OAuthClientSecret" -RSAPublicKey "$RSAPublicKey" -Key "$Key" -IV "$IV"
  3. 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'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Paylocity\lib\System.Data.CData.Paylocity.dll")
  2. 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()
  3. 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 Data

PowerShell

Update-Paylocity -Connection $Paylocity -Columns @('FirstName','LastName') -Values @('MyFirstName', 'MyLastName') -Table Employee -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("UPDATE Employee SET EmployeeId='1234' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Paylocity.PaylocityParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Paylocity Data

PowerShell

Add-Paylocity -Connection $Paylocity -Table Employee -Columns @("FirstName", "LastName") -Values @("MyFirstName", "MyLastName")

ADO.NET

$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("INSERT INTO Employee (EmployeeId) VALUES (@myEmployeeId)", $conn) $cmd.Parameters.Add(new System.Data.CData.Paylocity.PaylocityParameter("@myEmployeeId","1234")) $cmd.ExecuteNonQuery()

Delete Paylocity Data

PowerShell

Remove-Paylocity -Connection $Paylocity -Table "Employee" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Paylocity.PaylocityCommand("DELETE FROM Employee WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Paylocity.PaylocityParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()