Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created June 16, 2017 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dstreefkerk/780160fc3de4543d832d654436046be0 to your computer and use it in GitHub Desktop.
Save dstreefkerk/780160fc3de4543d832d654436046be0 to your computer and use it in GitHub Desktop.
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
$printJob.Delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment