Ready to get started?

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

Download Now

Pipe Sage 300 Data to CSV in PowerShell

Use standard PowerShell cmdlets to access Sage 300 tables.

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

Creating a Connection to Your Sage 300 Data

Sage 300 requires some initial setup in order to communicate over the Sage 300 Web API.

  • Set up the security groups for the Sage 300 user. Give the Sage 300 user access to the option under Security Groups (per each module required).
  • Edit both web.config files in the /Online/Web and /Online/WebApi folders; change the key AllowWebApiAccessForAdmin to true. Restart the webAPI app-pool for the settings to take.
  • Once the user access is configured, click https://server/Sage300WebApi/ to ensure access to the web API.

Authenticate to Sage 300 using Basic authentication.

Connect Using Basic Authentication

You must provide values for the following properties to successfully authenticate to Sage 300. Note that the provider reuses the session opened by Sage 300 using cookies. This means that your credentials are used only on the first request to open the session. After that, cookies returned from Sage 300 are used for authentication.

  • Url: Set this to the url of the server hosting Sage 300. Construct a URL for the Sage 300 Web API as follows: {protocol}://{host-application-path}/v{version}/{tenant}/ For example, http://localhost/Sage300WebApi/v1.0/-/.
  • User: Set this to the username of your account.
  • Password: Set this to the password of your account.

$conn = Connect-Sage300  -User "$User" -Password "$Password" -URL "$URL" -Company "$Company"

Selecting Data

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

Select-Sage300 -Connection $conn -Table OEInvoices | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myOEInvoicesData.csv -NoTypeInformation

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