Automate Sage Cloud Accounting Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Sage Cloud Accounting ADO.NET Provider

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



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

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

Cmdlets or ADO.NET?

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

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

You can connect to Sage Business Cloud Accounting using the embedded OAuth connectivity. When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.

PowerShell

  1. Install the module:

    Install-Module SageBCAccountingCmdlets
  2. Connect:

    $sagebcaccounting = Connect-SageBCAccounting
  3. Search for and retrieve data:

    $sent = "TRUE" $salesinvoices = Select-SageBCAccounting -Connection $sagebcaccounting -Table "SalesInvoices" -Where "sent = `'$sent`'" $salesinvoices

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

    $salesinvoices = Invoke-SageBCAccounting -Connection $sagebcaccounting -Query 'SELECT * FROM SalesInvoices WHERE sent = @sent' -Params @{'@sent'='TRUE'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.SageBCAccounting.SageBCAccountingConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SageBCAccountingDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT contact_name, total_amount from SalesInvoices" $da= New-Object System.Data.CData.SageBCAccounting.SageBCAccountingDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.contact_name $_.total_amount }

Update Sage Cloud Accounting Data

PowerShell

Update-SageBCAccounting -Connection $SageBCAccounting -Columns @('contact_name','total_amount') -Values @('Mycontact_name', 'Mytotal_amount') -Table SalesInvoices -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("UPDATE SalesInvoices SET sent='TRUE' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Sage Cloud Accounting Data

PowerShell

Add-SageBCAccounting -Connection $SageBCAccounting -Table SalesInvoices -Columns @("contact_name", "total_amount") -Values @("Mycontact_name", "Mytotal_amount")

ADO.NET

$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("INSERT INTO SalesInvoices (sent) VALUES (@mysent)", $conn) $cmd.Parameters.Add(new System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@mysent","TRUE")) $cmd.ExecuteNonQuery()

Delete Sage Cloud Accounting Data

PowerShell

Remove-SageBCAccounting -Connection $SageBCAccounting -Table "SalesInvoices" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("DELETE FROM SalesInvoices WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()