Batch Printing Tool in PowerShell
So, we had to think of how to achieve this. We had three options
- Buy an Commercial off the shelf (COTS) product. It might be limited, but would be supported and be easier to implement.
- Develop an application in house. Could be costly and difficult to support but could match all requirements.
- Have our System Integrator develop an application. As above, but a lot more expensive.
I had the task of bringing these options to life for our Design Group to make a decision on.
There were some constraints which made it more difficult e.g. our Printing and Enveloper wasn't able to distinguish between different page totals in jobs. This meant that our post room needed to print all 2 page letters, then 3 page letters and so on. This seemed bonkers to me, but the cost to replace this beast of a machine was too much to challenge this point.
I looked at various commercial products, some of the really good ones could print automatically, but given the above constraint it wasn't a viable solution.
I decided to try and build an application using PowerShell just to show what is possible if we had in-house developers.
My knowledge of creating UI's in PowerShell is limited to some horrible looking WinForms windows. I wanted to make something which looked delicious, or at least palatable to the average user and not look like Windows 98. I found Stephen Owen's website and this blog post series. Quite simply it is excellent.
With this knowledge in hand, I built the following GUI
The UI top box shows the output folders from our ERP system and provides some detail about each folder. Clicking expand will then fill the bottom section with all of the documents which are located within. This is gathered from a CSV file which is output from our ERP system when documents are generated for printing. If the user clicks on a document and clicks print, it will then add an entry in the CSV saying it has been printed and when. This will avoid other users printing the same document.
Clicking Archive will move the folder into an archive folder ready to be deleted. Clicking External will put the documents into a separate folder which will be sent to an external print house. This is used for massive print jobs, which is cheaper than doing it in-house.
To actually print from PowerShell is not an easy task to complete reliably. I found a tool called 2printer which works quite well. This is a pre-req for this tool to work.
I am sure that there is probably some .Net classes that I could use to do this natively, but given the time constraints, this seemed like a good option as a PoC.
The full code and folders and some sample files can be found at this GitHub repo
You just need to edit the folder locations at the bottom of the PowerShell script and you should be good to go.
We actually decided to go with a product called Print Conductor. It was really close to fulfilling our requirements, it was quick to deploy and it was fairly inexpensive.
The process of building a dummy application was great though and made our team think strongly about their requirements. I learnt quite a lot technically which is always a bonus!