Automatically clear an errored Print Spooler using PowerShell
Came across this issue due to users reporting printing PDFs from Microsoft Edge stops the print spooler on the print server. Quick solution is to check automatically for Errored jobs in the print spooler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #To run as a schedule task setup the following - powershell.exe -ExecutionPolicy Bypass C:\Clear_errored_spooler.ps1 Clear-Host $DateTime = Get-Date -Format G Start-Transcript -Path C:\QueueLog.txt -Append Write-Host "Checking printers and queues for errors" #Get any documents from all printers that in an error state $Errors = @(Get-Printer | Get-PrintJob | Where {$_.JobStatus -NotMatch "Printing|Printed"}).Count If ($Errors -gt 0) { Write-Warning "$DateTime - $Errors job(s) found in error in the print spooler, clearing!" Stop-Service spooler Start-Sleep -s 5 Remove-Item -Path "C:\Windows\System32\spool\PRINTERS\*.SPL" -Force Remove-Item -Path "C:\Windows\System32\spool\PRINTERS\*.SHD" -Force Start-Sleep -s 5 Start-Service spooler Write-Host "Printer queues have been cleared" } else { Write-Host "$DateTime - No job(s) found in error in the print spooler, exiting!" } Stop-Transcript Exit |