Ready to get started?

Learn more about the USPS PowerShell Cmdlets or download a free trial:

Download Now

Pipe USPS Data to CSV in PowerShell

Use standard PowerShell cmdlets to access USPS tables.

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

Creating a Connection to Your USPS Data

To authenticate with USPS, set the following connection properties.


The Cache Database




$conn = Connect-USPS  -PostageProvider "$PostageProvider" -RequestId "$RequestId" -Password "$Password" -AccountNumber "$AccountNumber"

Selecting Data

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

Select-USPS -Connection $conn -Table Senders | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySendersData.csv -NoTypeInformation

You will notice that we piped the results from Select-USPS 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.


Deleting Data

The following line deletes any records that match the criteria:

Select-USPS -Connection $conn -Table Senders -Where "SenderID = 25" | Remove-USPS

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

Import-Csv -Path C:\MySendersUpdates.csv | %{
  $record = Select-USPS -Connection $USPS -Table Senders -Where ("Id = `'"+$_.Id+"`'")
    Update-USPS -Connection $usps -Table Senders -Columns ("FirstName","Phone") -Values ($_.FirstName, $_.Phone) -Where ("Id = `'"+$_.Id+"`'")
