I have a third-party application that has so far talked to quickbooks using a plugin. This plugin no longer works with the latest versions of Windows, so I am replacing it with PowerShell scripts. The plugin will create a QBXMLRP.RequestProcessor com object, then open a connection and start a session with QuickBooks, process various requests from my application, and then close and disconnect the connection using quick books. While the connection is open, the ticket provided by QuickBooks is used to process any number of requests from my application.
Using PowerShell, I run a command prompt to launch PowerShell with the PowerShell.ps1 script running. As the plugin did, the PS script creates an instance of the com object, opens a qb connection, starts a qb session, sends a qb request, ends a qb session, closes the qb connection.
This works fine, except that unlike the plug-in, I cannot send multiple requests from my application in one open session with QuickBooks. As soon as I issue a command prompt, the PS script does this and the PS exits and the com object is lost. They still save a live instance of the qb com object and reuse it in subsequent PowerShell sessions ...
My application issues a command prompt to start PowerShell, which starts a qb session ...
(.ps1 script) $myqbxmrlp = New-Object -com QBXMLRP.RequestProcessor $myqbxmrlp.OpenConnection(...) $ticket = $myqbxmrlp.BeginSession(....) $ticket | Export-CliXml $ticket (or set-content) ?? preserve the live $myqbxmrlp com object ??
My application uses a command line call to open a PS session. Session 2 sends a request to qb ...
(.ps1 script) $myqbxmrlp = ?? get the live com object back ?? $ticket = Import-CliXml $ticket (or get-content) $myqbxmrlp.ProcessRequest($ticket,....)
Calling the command line to open a PS 3 session with a different request ...
Calling the command line to open a PS 4 session with a different request ...
Calling the command line to open a PS 5 session and end a qb session and close a qb connection ...
(.ps1 script) $myqbxmrlp = ?? get the com object back ?? $ticket = Import-CliXml $ticket (or get-content) myqbxmrlp.EndSession($ticket,....) $myqbxmrlp.CloseConnection
Is there any other way to approach this with powershell?