Clear a stuck print queue by resetting the spooler (PowerShell)
Stops the Print Spooler, deletes the queued spool files and starts the service again. Use it when a job is stuck and cannot be cancelled from the printer queue window.
Not yet tested
The script
<#
.SYNOPSIS
Clears a stuck print queue by resetting the Print Spooler service.
.DESCRIPTION
Stops the Spooler service, deletes the queued spool files, then starts the
service again. This clears ALL queued jobs on every printer on this
computer, not just the stuck one. The script asks for confirmation first. Use
-WhatIf to see what it would do without changing anything.
Must be run as Administrator.
.EXAMPLE
./Reset-PrintSpooler.ps1 -WhatIf
.EXAMPLE
./Reset-PrintSpooler.ps1
#>
#Requires -RunAsAdministrator
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param()
# $IsWindows does not exist in Windows PowerShell 5.1, so check the edition first
if ($PSVersionTable.PSEdition -eq 'Core' -and -not $IsWindows) {
Write-Error 'This script only works on Windows.'
exit 1
}
$service = Get-Service -Name Spooler -ErrorAction SilentlyContinue
if (-not $service) {
Write-Error 'The Print Spooler service was not found on this computer.'
exit 1
}
$spoolFolder = Join-Path -Path $env:SystemRoot -ChildPath 'System32\spool\PRINTERS'
$spoolFiles = @(Get-ChildItem -LiteralPath $spoolFolder -File -ErrorAction SilentlyContinue)
Write-Output "Spooler is $($service.Status). Queued spool files: $($spoolFiles.Count)."
if (-not $PSCmdlet.ShouldProcess('Print Spooler', 'Stop service and delete all queued jobs')) {
exit 0
}
$exitCode = 0
try {
Stop-Service -Name Spooler -Force -ErrorAction Stop
(Get-Service -Name Spooler).WaitForStatus('Stopped', [timespan]::FromSeconds(30))
# Read the folder again: jobs may have arrived since the count above
$spoolFiles = @(Get-ChildItem -LiteralPath $spoolFolder -File -ErrorAction Stop)
$spoolFiles | Remove-Item -Force -ErrorAction Stop
Write-Output "Deleted $($spoolFiles.Count) spool file(s)."
}
catch {
Write-Error "Reset failed: $($_.Exception.Message)"
$exitCode = 1
}
finally {
Start-Service -Name Spooler -ErrorAction SilentlyContinue
Write-Output "Spooler is now $((Get-Service -Name Spooler).Status)."
}
exit $exitCode
#Requires -RunAsAdministrator stops the script early if you forgot to elevate. SupportsShouldProcess gives you -WhatIf and -Confirm for free, and ConfirmImpact = 'High' means PowerShell asks you to confirm before the destructive part, even if you pass nothing.
Checks
The script exits with an error if it is not running on Windows or if the Spooler service does not exist. It then prints the service status and how many spool files are waiting, so you can see the problem before you fix it.
The confirmation point
$PSCmdlet.ShouldProcess() is where the prompt appears. With -WhatIf it prints what would happen and returns false, so the script exits without touching anything.
The reset
Stop-Service -Force stops the spooler and WaitForStatus waits up to 30 seconds for it to really stop, because the files stay locked until it does. The folder is read again at that point, in case new jobs arrived, and Remove-Item deletes the files.
Always restart
The finally block runs whether the reset worked or failed, so the spooler is never left stopped. If anything went wrong the script exits with code 1.
Cookies
No adverts, and nothing that follows you to another site. What we set is what signing in
and the forum need. We count page views with Umami, which sets no cookie and identifies nobody. The one exception is Google reCAPTCHA, which checks our forms are being used by
a person, and that one is yours to decline — nothing is loaded from Google until you
say so.
No adverts, and nothing that follows you to another site. We count page views without a cookie and identify nobody. Google reCAPTCHA checks our forms, and that one is yours to decline.
Cookie Policy ·
Privacy Policy