Ready to get started?

Download a free trial of the Sage 300 Data Provider to get started:

 Download Now

Learn more:

Sage 300 Icon Sage 300 ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Sage 300.

Automate Sage 300 Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Sage 300 data from PowerShell? This article demonstrates how to utilize the Sage 300 Cmdlets for tasks like connecting to Sage 300 data, automating operations, downloading data, 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.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Sage 300, 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.

Once you have acquired the necessary connection properties, accessing Sage 300 data in PowerShell can be enabled in three 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.

PowerShell

  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'}

ADO.NET

  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=http://127.0.0.1/Sage300WebApi/v1/-/;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 }