Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A quick PowerShell script to remove stale print jobs
# Jobs older than the below time will be deleted
$thresholdTime = (Get-Date).AddDays(-1)
# Get all current print jobs
$printJobs = Get-WmiObject Win32_PrintJob
ForEach ($printJob in $printJobs) {
# Convert the weird WMI time to a proper .NET DateTime object
$jobTime = [System.Management.ManagementDateTimeConverter]::ToDateTime($printJob.TimeSubmitted)
# If the job's TimeSubmitted falls outside of the threshold, delete it
if ($jobTime -lt $thresholdTime) {
$outputString = "Deleting job {0} by user {1} submitted on {2}" -f $printJob.JobId,$printJob.owner,$jobTime
Write-Verbose $outputString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.