Created
June 16, 2017 00:09
-
-
Save dstreefkerk/780160fc3de4543d832d654436046be0 to your computer and use it in GitHub Desktop.
A quick PowerShell script to remove stale print jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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