Printer queue

Powershell Tuesday Quick Tip #3

Printer Tricks

This week is a 2-for-Tuesday! Two basic printer tricks.
These come in really handy when troubleshooting the “I can’t print” help desk tickets. Like a lot of these types of one-liners, you have to be in the same domain as the target pc.

First, we can get the printer queue for a pc.

$pc =''
Get-WMIObject Win32_PerfFormattedData_Spooler_PrintQueue -ComputerName $pc|
Select-Object Name, @{Expression={$};Label='CurrentJobs'}, TotalJobsPrinted, JobErrors

Secondly, there is this one to clear the printer queue

$PC = ""
get-wmiobject win32_printer -filter “Name='MyPrinterName'” -ComputerName $pc|
foreach {Write-verbose “Cancelling all jobs on $($_.Name)” $_.CancelAllJobs()}

*Note: For the “Clear Print Jobs” snip to work, you need to know what the printer is called on the target pc.

That one is handy for those times when someone has tried to print a poorly formatted file that puts the printer’s PCL logic into a tailspin. You can reboot everything but until you cancel that job, the printer will keep getting bogged down. It’s especially fun when you have 10+ people sharing a printer. This way you can wrap a “foreach” loop around the code and “Bob’s your uncle!”

Until next time!