Ready to get started?

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

 Download Now

Learn more:

Sage 200 Icon Sage 200 ADO.NET Provider

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

Automate Sage 200 Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Sage 200 data from PowerShell? This article demonstrates how to utilize the Sage 200 Cmdlets for tasks like connecting to Sage 200 data, automating operations, downloading data, and more.

The CData Cmdlets for Sage 200 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 200.

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing Sage 200 data in PowerShell can be enabled in three steps.

  • Schema: Determines which Sage 200 edition you are connecting to. Specify either StandardUK or ProfessionalUK.
  • Subscription Key: Provides access to the APIs that are used to establish a connection. You will first need to log into the Sage 200 API website and subscribe to the API edition that matches your account. You can do so here: https://developer.columbus.sage.com/docs/services/api/uk. Afterwards, the subscription key may be found in your profile after logging into Sage 200.

PowerShell

  1. Install the module:

    Install-Module Sage200Cmdlets
  2. Connect:

    $sage200 = Connect-Sage200 -SubscriptionKey "$SubscriptionKey" -Schema "$Schema"
  3. Search for and retrieve data:

    $code = "12345" $banks = Select-Sage200 -Connection $sage200 -Table "Banks" -Where "Code = `'$Code`'" $banks

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

    $banks = Invoke-Sage200 -Connection $sage200 -Query 'SELECT * FROM Banks WHERE Code = @Code' -Params @{'@Code'='12345'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Sage200.Sage200Connection("SubscriptionKey=12345;Schema=StandardUK;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the Sage200DataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, Code from Banks" $da= New-Object System.Data.CData.Sage200.Sage200DataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.code }