Viewing Print Queue Statistics with PowerShell

Leveraging WMI, you can easily view and manipulate print queues on a print server via PowerShell.  You can do anything from building a Print Queue, deleting a print queue and cancelling all print jobs on an existing queue. You can also use a specific WMI class to view all print jobs that have been processed since the last reboot of a print server or the last service reset of the Print Spooler service on the print server.

While I will not go into how to build a print queue or set up a printer using PowerShell, these links here will show you some great examples on performing this. Instead, my focus in this blog post will show you how easily it is to view the statistics of each print queue on a print server or locally connected printer.

Print Server Statistics

Using the Win32_PerfFormattedData_Spooler_PrintQueue class, you can easily see what printer queues are being used and which ones are not.  The statistics reset themselves when the Print Spooler service is restarted. So if a print server is rebooted, all of the data is reset.  One thing I found while playing with this is that if the printer is not connected to the server or if the printer is turned off, then the statistics will not be reset even if the spooler service has been restarted.  The only way for the statistics to be reset is to power on the printer or reconnect it to the server and perform the spooler reset. Using the following one-liner, you can see which queues have been used along with any that might have had an error at some point in time.

Get-WMIObject Win32_PerfFormattedData_Spooler_PrintQueue |
 Select Name, @{Expression={$_.jobs};Label="CurrentJobs"}, TotalJobsPrinted, JobErrors

Untitled

As it shows, I have one job currently being processed and two jobs total have been sent through the print spooler.  Keep in mind that this is done from my laptop, so running this against a print server hosting many more printers will be more impressive.

Using this on a print server would be great to find old print queues that may remain even after a printer has long since been decommissioned or to see what printers are seeing the most usage.

Putting this into a excel spreadsheet is as simple as piping it into an Export-CSV command. You could even set up a scheduled job that checks each print server once a week and email the results to an individual or group for analysis.

This entry was posted in powershell and tagged , , . Bookmark the permalink.

9 Responses to Viewing Print Queue Statistics with PowerShell

  1. Chinmay Joshi says:

    I would like to check “Printer status” daily. Could you let me know the script or command so that i can schedule the same.

  2. Pingback: Powershell – Statistik der Druckaufträge per PowerShell auslesen | Nerd IG

  3. Pingback: How To Fix Powershell Clear Print Spooler in Windows

  4. Glen says:

    I would like a script that not only checks the status of the queue but restarts the print spooler service if anything is stuck in there. Could that be easily added?

  5. Nicolas says:

    Would it be possible to return results only for a certain date range? As in, to see how many documents printed to a queue between 1 October 2012 through 31 October 2012?

    • Boe Prox says:

      You won’t be able to get that type of information from WMI. But you can look in the System log of the print server (I can’t remember the ID off of the top of my head) and you could then set a range to search for using Get-EventLog or Get-WinEvent and pipe that into Measure-Object to get the number of documents printed during that time frame.

  6. Pingback: Tweets that mention Viewing Print Queue Statistics with PowerShell | Learn Powershell | Achieve More -- Topsy.com

Leave a comment