Pipe Paylocity Data to CSV in PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Paylocity Data Cmdlets

An 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.



Use standard PowerShell cmdlets to access Paylocity tables.

The CData Cmdlets Module for Paylocity is a standard PowerShell module offering straightforward integration with Paylocity. Below, you will find examples of using our Paylocity Cmdlets with native PowerShell cmdlets.

Creating a Connection to Your Paylocity Data

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.

$conn = Connect-Paylocity  -OAuthClientID "$OAuthClientID" -OAuthClientSecret "$OAuthClientSecret" -RSAPublicKey "$RSAPublicKey" -Key "$Key" -IV "$IV"

Selecting Data

Follow the steps below to retrieve data from the Employee table and pipe the result into to a CSV file:

Select-Paylocity -Connection $conn -Table Employee | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myEmployeeData.csv -NoTypeInformation

You will notice that we piped the results from Select-Paylocity into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.

Deleting Data

The following line deletes any records that match the criteria:

Select-Paylocity -Connection $conn -Table Employee -Where "EmployeeId = 1234" | Remove-Paylocity

Inserting and Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Paylocity, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyEmployeeUpdates.csv | %{
  $record = Select-Paylocity -Connection $Paylocity -Table Employee -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-Paylocity -Connection $paylocity -Table Employee -Columns ("FirstName","LastName") -Values ($_.FirstName, $_.LastName) -Where ("Id = `'"+$_.Id+"`'")
  }else{
    Add-Paylocity -Connection $paylocity -Table Employee -Columns ("FirstName","LastName") -Values ($_.FirstName, $_.LastName)
  }
}

As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!