![]() |
VOOZH | about |
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.
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.
Authenticate to Sage 300 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.
Install the module:
Install-Module Sage300Cmdlets
Connect:
$sage300 = Connect-Sage300 -User "$User" -Password "$Password" -URL "$URL" -Company "$Company"
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'}
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")
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()
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
}
Download a free trial of the Sage 300 Data Provider to get started:
Download NowLearn more:
👁 Sage 300 IconRapidly create and deploy powerful .NET applications that integrate with Sage 300.