What It Does
When there are queued jobs older than MinAgeMinutes, the script stops the Print Spooler service and the services that depend on it, deletes those job files from the spool folder, starts the spooler again and checks that it is running. The script does not restart dependent services it stopped.
The age cutoff applies to each file in the spool folder across all printers, including files for jobs that were waiting normally. The result count is queued files, and files newer than MinAgeMinutes are kept. Users may have to send their jobs again. It never removes a printer, a driver or a port.
If no jobs meet the age cutoff, it leaves a running spooler alone or starts a stopped one.
Before You Run It
- Tell the users first. Every queued job old enough is cancelled, on every printer on the machine.
- On a print server, set MinAgeMinutes so jobs that are printing normally are not caught.
- If the same printer jams the queue every week, check the driver too. This clears the jobs.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
- What it changes: Stops and starts the Print Spooler; deletes queued print jobs.
- Restart: It never restarts the machine.
- Typical run: Under 30 seconds.
- Example answer: "Cleared 4 stuck print jobs; Print Spooler running"
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- MinAgeMinutes: Only delete job files at least this many minutes old, so a job being printed right now survives. Whole number, 0 to 1440. Default 0 (all).
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.