Remove Print Job Error thru PowerShell

Recently I was working on building a printer management solution using Powershell where admins can input the printer name and remove the error from the print queue.

Our print servers are running windows 2008 & admin server is windows 2008 R2 from where we run scripts or scripting solutions.

Printer management Module is available for windows 2012 & above, for 2008 server as this is not available So on researching, found below function in script gallery that uses WMI.

I have written the solution based on  this function but unfortunately the command was only working when run locally to the server, running it remotely was returning nothing.

Get-LHSPrintJob -ComputerName Server1 | where {$_.Status -eq ‘Error’} | Foreach-Object { $_.Delete() }

On troubleshooting I have found that running Win32_Printer class runs fine remotely.

Get-WmiObject -Class Win32_Printer -ComputerName server01

On the other hand Win32_Printjob doesn’t return anything.

Get-WmiObject -Class Win32_PrintJob -ComputerName server01

Same WMI command returns the correct status on running locally to the server.

So this solution was useful only when We are running our scripting solution local to the print server.

We changed our strategy & instead of using windows 2008 R2,We are now using windows 2012 R2 as our administration server.

Windows 2012 R2 comes with Print management module so I ran below PS command for feasibility check but received error:

Get-PrintJob -ComputerName server01 -PrinterName Printer-1

As per error, Spooler service was not running , so I started the spooler service and error disappeared.

Now you can use where clause & select Jobstatus like error*, this can be than piped to Remove-PrintJob to remove the error job.

If you want to do avoid complexities of WMI and want to automate most of the printer related tasks than use windows 2012 or above as it makes the things really easy but if you can’t do that than there are other ways like remote powershell session or psexec legacy method. I have the advantage of choosing the version so We avoided the complexities of using older versions.

Thanks for reading

Sukhija Vikas


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s