Automate QuickBooks Integration Tasks from PowerShell
The CData ADO.NET Provider for QuickBooks 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 QuickBooks.
About QuickBooks Data Integration
CData simplifies access and integration of live QuickBooks data. Our customers leverage CData connectivity to:
- Access both local and remote company files.
- Connect across editions and regions: QuickBooks Premier, Professional, Enterprise, and Simple Start edition 2002+, as well as Canada, New Zealand, Australia, and UK editions from 2003+.
- Use SQL stored procedures to perform actions like voiding or clearing transactions, merging lists, searching entities, and more.
Customers regularly integrate their QuickBooks data with preferred tools, like Power BI, Tableau, or Excel, and integrate QuickBooks data into their database or data warehouse.
Getting Started
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for QuickBooks; this tutorial shows how to use the Provider to create, retrieve, update, and delete QuickBooks data.
Once you have acquired the necessary connection properties, accessing QuickBooks data in PowerShell can be enabled in three steps.
When you are connecting to a local QuickBooks instance, you do not need to set any connection properties.
Requests are made to QuickBooks through the Remote Connector. The Remote Connector runs on the same machine as QuickBooks and accepts connections through a lightweight, embedded Web server. The server supports SSL/TLS, enabling users to connect securely from remote machines.
The first time you connect, authorize the Remote Connector with QuickBooks. See the "Getting Started" chapter of the help documentation for a guide.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for QuickBooks\lib\System.Data.CData.QuickBooks.dll") -
Connect to QuickBooks:
$conn= New-Object System.Data.CData.QuickBooks.QuickBooksConnection("URL=http://remotehost:8166;User=admin;Password=admin123;") $conn.Open() -
Instantiate the QuickBooksDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, CustomerBalance from Customers" $da= New-Object System.Data.CData.QuickBooks.QuickBooksDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.customerbalance }
Update QuickBooks Data
$cmd = New-Object System.Data.CData.QuickBooks.QuickBooksCommand("UPDATE Customers SET Type='Commercial' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooks.QuickBooksParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert QuickBooks Data
$cmd = New-Object System.Data.CData.QuickBooks.QuickBooksCommand("INSERT INTO Customers (Type) VALUES (@myType)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooks.QuickBooksParameter("@myType","Commercial")))
$cmd.ExecuteNonQuery()
Delete QuickBooks Data
$cmd = New-Object System.Data.CData.QuickBooks.QuickBooksCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooks.QuickBooksParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject