![]() |
VOOZH | about |
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.
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.
Install the module:
Install-Module Sage200Cmdlets
Connect:
$sage200 = Connect-Sage200 -SubscriptionKey "$SubscriptionKey" -Schema "$Schema" -InitiateOAuth "$InitiateOAuth"
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'}
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")
Connect to Sage 200:
$conn= New-Object System.Data.CData.Sage200.Sage200Connection("SubscriptionKey=12345;Schema=StandardUK;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
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
}
Download a free trial of the Sage 200 Data Provider to get started:
Download NowLearn more:
👁 Sage 200 IconRapidly create and deploy powerful .NET applications that integrate with Sage 200.