-
Notifications
You must be signed in to change notification settings - Fork 5
print_queue_reset.ps1
Resets and clears the Windows print queue by removing stuck or corrupted print jobs.
This script provides a comprehensive solution for resolving common printing issues by stopping the Print Spooler service, clearing all queued print jobs, and restarting the service. It includes intelligent retry logic and graceful handling of locked files.
This script resets and clears the Windows print queue by stopping the Print Spooler service, removing all queued print jobs from the spooler directory, and restarting the service. This resolves common printing issues caused by stuck or corrupted print jobs that prevent new documents from printing.
- Windows operating system
- Administrator privileges (required to manage services and delete files)
- Print Spooler service must exist on the system
All inputs are hardcoded in the script:
-
$serviceName: Name of the Print Spooler service (default: "Spooler") -
$stopTimeout: Maximum seconds to wait for service to stop (default: 30) -
$startTimeout: Maximum seconds to wait for service to start (default: 30)
- Service stop timeout: 30 seconds
- Service start timeout: 30 seconds
- Spooler directory: %SystemRoot%\System32\spool\PRINTERS
- File removal retry attempts: 3 per file
- Retry delay: 500 milliseconds between attempts
The script performs the following operations in sequence:
- Validates hardcoded input values
- Checks current status of Print Spooler service
- Stops the Print Spooler service if running and waits for handles to release
- Attempts to remove print job files with retry logic (3 attempts per file)
- Reports successfully removed and locked files separately
- Restarts the Print Spooler service (locked files removed on restart)
- Verifies service is running and reports final status
- Hardcoded service name and timeout values
- System spooler directory path (
$env:SystemRoot\System32\spool\PRINTERS) - Windows Print Spooler service status
- No secrets in logs
- Requires elevated privileges to modify system services
- Only deletes files from the Windows spooler directory
- Uses
-Forceparameter for file removal operations
None - Local system operations only
- 0 = Success - Print queue cleared and service restarted
- 1 = Failure - Input validation failed, service operations failed, or errors
[ INPUT VALIDATION ]
--------------------------------------------------------------
Service name validated
Stop timeout validated
Start timeout validated
[ SERVICE STATUS CHECK ]
--------------------------------------------------------------
Service : Spooler
Status : Running
[ STOPPING PRINT SPOOLER ]
--------------------------------------------------------------
Stopping service Spooler
Service stopped successfully
Waiting for file handles to release...
[ CLEARING PRINT QUEUE ]
--------------------------------------------------------------
Spooler Directory : C:\Windows\System32\spool\PRINTERS
Total Files Found : 5
Removing files...
Files Removed : 5
Queue cleared successfully
[ STARTING PRINT SPOOLER ]
--------------------------------------------------------------
Starting service Spooler
Service started successfully
[ FINAL STATUS ]
--------------------------------------------------------------
Service : Spooler
Status : Running
Result : Print queue cleared and service restarted successfully
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
- v1.1.0 (2025-01-17) - Add retry logic and handle locked files gracefully
- v1.0.1 (2025-01-17) - Fix Count property error for single file case
- v1.0.0 (2025-01-17) - Initial release - Print queue reset script
- View Script Source
- Scripts - Back to script index