Ready to get started?

Learn more about the CData ADO.NET Provider for Sage 300 or download a free trial:

Download Now

Automate Sage 300 Integration Tasks from PowerShell

Are you looking for a quick and easy way to access Sage 300 data from PowerShell? We show how to use the Cmdlets for Sage 300 and the CData ADO.NET Provider for Sage 300 to connect to Sage 300 data and synchronize, automate, download, and more.

The CData Cmdlets for Sage 300 are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Sage 300.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Sage 300 API, but also an SQL interface; this tutorial shows how to use both to retrieve Sage 300 data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Sage 300. To access Sage 300 data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Sage 300.

After obtaining the needed connection properties, accessing Sage 300 data in PowerShell consists of three basic steps.

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.


  1. Install the module:

    Install-Module Sage300Cmdlets
  2. Connect:

    $sage300 = Connect-Sage300 -User "$User" -Password "$Password" -URL "$URL" -Company "$Company"
  3. Search for and retrieve data:

    $allowpartialshipments = "Yes" $oeinvoices = Select-Sage300 -Connection $sage300 -Table "OEInvoices" -Where "AllowPartialShipments = `'$AllowPartialShipments`'" $oeinvoices

    You can also use the Invoke-Sage300 cmdlet to execute SQL commands:

    $oeinvoices = Invoke-Sage300 -Connection $sage300 -Query 'SELECT * FROM OEInvoices WHERE AllowPartialShipments = @AllowPartialShipments' -Params @{'@AllowPartialShipments'='Yes'}


  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Sage 300\lib\System.Data.CData.Sage300.dll")
  2. Connect to Sage 300:

    $conn= New-Object System.Data.CData.Sage300.Sage300Connection("User=SAMPLE;Password=password;URL=;Company=SAMINC;") $conn.Open()
  3. Instantiate the Sage300DataAdapter, execute an SQL query, and output the results:

    $sql="SELECT InvoiceUniquifier, ApprovedLimit from OEInvoices" $da= New-Object System.Data.CData.Sage300.Sage300DataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.invoiceuniquifier $_.approvedlimit }