Ready to get started?

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

Download Now

Pipe FedEx Data to CSV in PowerShell

Use standard PowerShell cmdlets to access FedEx tables.

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

Creating a Connection to Your FedEx Data

There are five pieces of information needed in order to authenticate its actions with the FedEx service. This information is below.

  • Server: This controls the URL where the requests should be sent. Common testing options for this are: "https://gatewaybeta.fedex.com:443/xml", "https://wsbeta.fedex.com:443/xml", "https://gatewaybeta.fedex.com:443/web-service", and "https://wsbeta.fedex.com:443/web-service"
  • DeveloperKey: This is the identifier part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • Password: This is the secret part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
  • AccountNumber: This valid 9-digit FedEx account number is used for logging into the FedEx server.
  • MeterNumber: This value is used for submitting requests to FedEx. This value will be provided to you by FedEx after registration.
  • PrintLabelLocation: This property is required if one intends to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

The Cache Database

Many of the useful tasks available from FedEx require a lot of data. To ensure this data is easy to input and recall later, utilizes a cache database to make these requests. You must set the cache connection properties:

  • CacheProvider: The specific database you are using to cache with. For example, org.sqlite.JDBC.
  • CacheConnection: The connection string to be passed to the cache provider. For example, jdbc:sqlite:C:\users\username\documents\fedexcache.db

$conn = Connect-FedEx  -Server "$Server" -DeveloperKey "$DeveloperKey" -Password "$Password" -AccountNumber "$AccountNumber" -MeterNumber "$MeterNumber" -PrintLabelLocation "$PrintLabelLocation" -CacheProvider "$CacheProvider" -CacheConnection "$CacheConnection"

Selecting Data

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

Select-FedEx -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-FedEx 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-FedEx -Connection $conn -Table Senders -Where "SenderID = ab26f704-5edf-4a9f-9e4c-25" | Remove-FedEx

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

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

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!