Automate Exact Online Integration Tasks from PowerShell
The CData ADO.NET Provider for Exact Online is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Exact Online.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Exact Online; this tutorial shows how to use the Provider to create, retrieve, update, and delete Exact Online data.
Once you have acquired the necessary connection properties, accessing Exact Online data in PowerShell can be enabled in three steps.
Exact Online uses the OAuth authentication standard. The InitiateOAuth connection property facilitates the OAuth flow -- by default, this is set to GETANDREFRESH. You can also use the embedded OAuth credentials or you can register an OAuth app with Exact to obtain your own. In addition to the OAuth values, provide the Region. If Division is not set, the default Division is determined.
See the "Getting Started" chapter of the help documentation for more information.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Exact Online\lib\System.Data.CData.ExactOnline.dll") -
Connect to Exact Online:
$conn= New-Object System.Data.CData.ExactOnline.ExactOnlineConnection("Region='United States';Division=5512;InitiateOAuth=GETANDREFRESH;") $conn.Open() -
Instantiate the ExactOnlineDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, CreditLinePurchase from Accounts" $da= New-Object System.Data.CData.ExactOnline.ExactOnlineDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.creditlinepurchase }
Update Exact Online Data
$cmd = New-Object System.Data.CData.ExactOnline.ExactOnlineCommand("UPDATE Accounts SET IsCompetitor='False' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ExactOnline.ExactOnlineParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Exact Online Data
$cmd = New-Object System.Data.CData.ExactOnline.ExactOnlineCommand("INSERT INTO Accounts (IsCompetitor) VALUES (@myIsCompetitor)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ExactOnline.ExactOnlineParameter("@myIsCompetitor","False")))
$cmd.ExecuteNonQuery()
Delete Exact Online Data
$cmd = New-Object System.Data.CData.ExactOnline.ExactOnlineCommand("DELETE FROM Accounts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ExactOnline.ExactOnlineParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject