Skip to content

print_queue_clear.ps1

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

print_queue_clear.ps1

Resets and clears the Windows print queue by stopping the Print Spooler service.

Overview

This script resolves common printing issues caused by stuck or corrupted print jobs by stopping the Print Spooler service, removing all queued print jobs from the spooler directory, and restarting the service.

Purpose

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. Resolves common printing issues caused by stuck or corrupted print jobs.

Prerequisites

  • Windows 10/11 or Windows Server
  • Administrator privileges
  • Print Spooler service must exist

Configuration

Required Inputs

  • $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)

Behavior

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

Security Notes

  • No secrets in logs
  • Requires elevated privileges
  • Only deletes files from Windows spooler directory

Exit Codes

  • 0 = Success
  • 1 = Failure

Example Output

[ SERVICE STATUS CHECK ]
--------------------------------------------------------------
Service : Spooler
Status  : Running

[ STOPPING PRINT SPOOLER ]
--------------------------------------------------------------
Stopping service Spooler
Service stopped successfully

[ CLEARING PRINT QUEUE ]
--------------------------------------------------------------
Spooler Directory : C:\Windows\System32\spool\PRINTERS
Total Files Found : 5
Files Removed     : 5
Queue cleared successfully

[ STARTING PRINT SPOOLER ]
--------------------------------------------------------------
Service started successfully

[ FINAL STATUS ]
--------------------------------------------------------------
Result : Print queue cleared and service restarted successfully

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • 2024-12-01 v1.1.0 - Migrated from SuperOps - added retry logic for locked files
  • 2025-01-17 v1.0.0 - Initial release

Links

Clone this wiki locally