Skip to content

print_queue_reset.ps1

Corey Watson edited this page Dec 19, 2025 · 1 revision

print_queue_reset.ps1

Resets and clears the Windows print queue by removing stuck or corrupted print jobs.

Overview

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.

Purpose

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.

Prerequisites

  • Windows operating system
  • Administrator privileges (required to manage services and delete files)
  • Print Spooler service must exist on the system

Configuration

Required Inputs

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)

Settings

  • 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

Behavior

The script performs the following operations in sequence:

  1. Validates hardcoded input values
  2. Checks current status of Print Spooler service
  3. Stops the Print Spooler service if running and waits for handles to release
  4. Attempts to remove print job files with retry logic (3 attempts per file)
  5. Reports successfully removed and locked files separately
  6. Restarts the Print Spooler service (locked files removed on restart)
  7. Verifies service is running and reports final status

Data Sources & Priority

  1. Hardcoded service name and timeout values
  2. System spooler directory path ($env:SystemRoot\System32\spool\PRINTERS)
  3. Windows Print Spooler service status

Security Notes

  • No secrets in logs
  • Requires elevated privileges to modify system services
  • Only deletes files from the Windows spooler directory
  • Uses -Force parameter for file removal operations

Endpoints

None - Local system operations only

Exit Codes

  • 0 = Success - Print queue cleared and service restarted
  • 1 = Failure - Input validation failed, service operations failed, or errors

Example Output

[ 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 ]
--------------------------------------------------------------

Version History

  • 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

Links

Clone this wiki locally