Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate QuickBooks POS Integration Tasks from PowerShell
Are you in search of a quick and easy way to access QuickBooks POS data from PowerShell? This article demonstrates how to utilize the QuickBooks POS Cmdlets for tasks like connecting to QuickBooks POS data, automating operations, downloading data, and more.
The CData Cmdlets for QuickBooks POS 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 POS.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to QuickBooks POS, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete QuickBooks POS data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for QuickBooks POS. To access QuickBooks POS data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for QuickBooks POS.
Once you have acquired the necessary connection properties, accessing QuickBooks POS 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 POS through the Remote Connector. The Remote Connector runs on the same machine as QuickBooks POS 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 POS. See the "Getting Started" chapter of the help documentation for a guide.
PowerShell
-
Install the module:
Install-Module QuickBooksPOSCmdlets
-
Connect:
$quickbookspos = Connect-QBPOS
-
Search for and retrieve data:
$lastname = "Cook" $customers = Select-QBPOS -Connection $quickbookspos -Table "Customers" -Where "LastName = `'$LastName`'" $customers
You can also use the Invoke-QBPOS cmdlet to execute SQL commands:
$customers = Invoke-QBPOS -Connection $quickbookspos -Query 'SELECT * FROM Customers WHERE LastName = @LastName' -Params @{'@LastName'='Cook'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for QuickBooks POS\lib\System.Data.CData.QuickBooksPOS.dll")
-
Connect to QuickBooks POS:
$conn= New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSConnection("") $conn.Open()
-
Instantiate the QuickBooksPOSDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ListId, AccountLimit from Customers" $da= New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.listid $_.accountlimit }
Update QuickBooks POS Data
PowerShell
Update-QBPOS -Connection $QuickBooksPOS -Columns @('ListId','AccountLimit') -Values @('MyListId', 'MyAccountLimit') -Table Customers -Id "MyListId"
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSCommand("UPDATE Customers SET LastName='Cook' WHERE ListId = @myListId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSParameter("@myListId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert QuickBooks POS Data
PowerShell
Add-QBPOS -Connection $QuickBooksPOS -Table Customers -Columns @("ListId", "AccountLimit") -Values @("MyListId", "MyAccountLimit")
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSCommand("INSERT INTO Customers (LastName) VALUES (@myLastName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSParameter("@myLastName","Cook")))
$cmd.ExecuteNonQuery()
Delete QuickBooks POS Data
PowerShell
Remove-QBPOS -Connection $QuickBooksPOS -Table "Customers" -Id "MyListId"
ADO.NET
$cmd = New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSCommand("DELETE FROM Customers WHERE ListId=@myListId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.QuickBooksPOS.QuickBooksPOSParameter("@myListId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject