Automate QuickBooks Integration Tasks from PowerShell



Are you in search of a quick and easy way to access QuickBooks data from PowerShell? This article demonstrates how to utilize the QuickBooks Cmdlets for tasks like connecting to QuickBooks data, automating operations, downloading data, and more.

The CData Cmdlets for QuickBooks 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 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


PowerShell Cmdlets or ADO.NET Provider?

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

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, you will need to authorize the Remote Connector with QuickBooks. See the "Getting Started" chapter of the help documentation for a guide.

PowerShell

  1. Install the module:

    Install-Module QuickBooksCmdlets
  2. Connect:

    $quickbooks = Connect-QB -URL "$URL" -User "$User" -Password "$Password"
  3. Search for and retrieve data:

    $type = "Commercial" $customers = Select-QB -Connection $quickbooks -Table "Customers" -Where "Type = `'$Type`'" $customers

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

    $customers = Invoke-QB -Connection $quickbooks -Query 'SELECT * FROM Customers WHERE Type = @Type' -Params @{'@Type'='Commercial'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.QuickBooks.QuickBooksConnection("URL=http://remotehost:8166;User=admin;Password=admin123;") $conn.Open()
  3. 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

PowerShell

Update-QB -Connection $QuickBooks -Columns @('Name','CustomerBalance') -Values @('MyName', 'MyCustomerBalance') -Table Customers -Id "MyId"

ADO.NET

$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

PowerShell

Add-QB -Connection $QuickBooks -Table Customers -Columns @("Name", "CustomerBalance") -Values @("MyName", "MyCustomerBalance")

ADO.NET

$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

PowerShell

Remove-QB -Connection $QuickBooks -Table "Customers" -Id "MyId"

ADO.NET

$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()

Ready to get started?

Download a free trial of the QuickBooks Data Provider to get started:

 Download Now

Learn more:

QuickBooks Icon QuickBooks ADO.NET Provider

Complete read-write access to QuickBooks enables developers to search (Customers, Transactions, Invoices, Sales Receipts, etc.), update items, edit customers, and more, from any .NET application.