Avilith – Scripts

Clear Print Spooler

Category: Windows Maintenance

Back to Scripts

Stops the print spooler service, clears queued print jobs from the spool folder, and restarts the service to resolve common printing issues.Stops the print spooler service, clears queued print jobs from the spool folder, and restarts the service to resolve common printing issues.Stops the print spooler service, clears queued print jobs from the spool folder, and restarts the service to resolve common printing issues.


Write-Host "Stopping the Print Spooler service..." -ForegroundColor Yellow
try {
    Stop-Service -Name Spooler -Force -ErrorAction Stop
    Write-Host "Print Spooler stopped successfully." -ForegroundColor Green
} catch {
    Write-Host "Failed to stop the Print Spooler: $_" -ForegroundColor Red
    exit 1
}

$spoolDir = "$env:windir\System32\spool\PRINTERS"
Write-Host "Clearing spool folder: $spoolDir" -ForegroundColor Yellow
try {
    Remove-Item "$spoolDir\*" -Force -Recurse -ErrorAction Stop
    Write-Host "Spool folder cleared." -ForegroundColor Green
} catch {
    Write-Host "Failed to clear spool folder: $_" -ForegroundColor Red
    exit 1
}

Write-Host "Starting the Print Spooler service..." -ForegroundColor Yellow
try {
    Start-Service -Name Spooler -ErrorAction Stop
    Write-Host "Print Spooler started successfully." -ForegroundColor Green
} catch {
    Write-Host "Failed to start the Print Spooler: $_" -ForegroundColor Red
    exit 1
}

Write-Host "Print spooler reset complete." -ForegroundColor Cyan

        

Comments

Log in to leave a comment.