How to pipe ADP Data to CSV in PowerShell



Use standard PowerShell cmdlets to access ADP tables.

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

Creating a Connection to Your ADP Data

Connect to ADP by specifying the following properties:

  • SSLClientCert: Set this to the certificate provided during registration.
  • SSLClientCertPassword: Set this to the password of the certificate.
  • UseUAT: The connector makes requests to the production environment by default. If using a developer account, set UseUAT = true.
  • RowScanDepth: The maximum number of rows to scan for the custom fields columns available in the table. The default value will be set to 100. Setting a high value may decrease performance.

The connector uses OAuth to authenticate with ADP. OAuth requires the authenticating user to interact with ADP using the browser. For more information, refer to the OAuth section in the Help documentation.

$conn = Connect-ADP  -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -SSLClientCert "$SSLClientCert" -SSLClientCertPassword "$SSLClientCertPassword"

Selecting Data

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

Select-ADP -Connection $conn -Table Workers | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myWorkersData.csv -NoTypeInformation

You will notice that we piped the results from Select-ADP 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-ADP -Connection $conn -Table Workers -Where "AssociateOID = G3349PZGBADQY8H8" | Remove-ADP

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 ADP, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyWorkersUpdates.csv | %{
  $record = Select-ADP -Connection $ADP -Table Workers -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-ADP -Connection $adp -Table Workers -Columns ("AssociateOID","WorkerID") -Values ($_.AssociateOID, $_.WorkerID) -Where ("Id = `'"+$_.Id+"`'")
  }else{
    Add-ADP -Connection $adp -Table Workers -Columns ("AssociateOID","WorkerID") -Values ($_.AssociateOID, $_.WorkerID)
  }
}

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!

Ready to get started?

Download a free trial of the ADP Cmdlets to get started:

 Download Now

Learn more:

ADP Icon ADP Data Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to ADP. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.