Ready to get started?

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

Download Now

Pipe Epicor ERP Data to CSV in PowerShell

Use standard PowerShell cmdlets to access Epicor ERP tables.

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

Creating a Connection to Your Epicor ERP Data

To successfully connect to your ERP instance, you must specify the following connection properties:

  • Url:the URL of the server hosting your ERP instance. For example, https://myserver.EpicorSaaS.com
  • ERPInstance: the name of your ERP instance.
  • User: the username of your account.
  • Password: the password of your account.
  • Service: the service you want to retrieve data from. For example, BaqSvc.

In addition, you may also set the optional connection properties:

  • ApiKey: An optional key that may be required for connection to some services depending on your account configuration.
  • ApiVersion: Defaults to v1. May be set to v2 to use the newer Epicor API.
  • Company: Required if you set the ApiVersion to v2.

$conn = Connect-EpicorERP  -ervice "$ervice" -ERPInstance "$ERPInstance" -URL "$URL" -User "$User" -Password "$Password"

Selecting Data

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

Select-EpicorERP -Connection $conn -Table Customers | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myCustomersData.csv -NoTypeInformation

You will notice that we piped the results from Select-EpicorERP 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-EpicorERP -Connection $conn -Table Customers -Where "CompanyName = CompanyName" | Remove-EpicorERP

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

Import-Csv -Path C:\MyCustomersUpdates.csv | %{
  $record = Select-EpicorERP -Connection $EpicorERP -Table Customers -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-EpicorERP -Connection $epicorerp -Table Customers -Columns ("CustNum","Company") -Values ($_.CustNum, $_.Company) -Where ("Id = `'"+$_.Id+"`'")
  }else{
    Add-EpicorERP -Connection $epicorerp -Table Customers -Columns ("CustNum","Company") -Values ($_.CustNum, $_.Company)
  }
}

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!