Deletes Paused – Spooling print jobs that are older than 12 hours
$PrintJobs = get-wmiobject -class "Win32_PrintJob" -namespace “root\CIMV2” -computername . | Where-Object { $_.JobStatus -eq "Paused | Spooling" -and [System.Management.ManagementDateTimeConverter]::ToDateTime($_.TimeSubmitted) -lt $($(Get-Date).addHours(-12))}
foreach ($job in $PrintJobs)
{
Write-Host “Canceling job $($job.JobId)”
Write-Host “Document: $($job.Document)”
Write-Host “Owner: $($job.Owner)”
$job.Delete() }
Thanks!
My own script ended up more simple, since I only needed deletion of print jobs of 30 minutes or older. First test seems promising:
$PrintJobs = get-wmiobject -class “Win32_PrintJob” -namespace “root\CIMV2” -computername . | Where-Object { $_.StartTime -lt $($(Get-Date).addMinutes(-30)) }
foreach ($job in $PrintJobs) {
Write-Host “Canceling job $($job.JobId)”
$job.Delete()
}
Final Script being run via following Task Managed batch file (powershell -noprofile -noexit -executionpolicy bypass -file “C:\Scripts\Delete_Printjobs.ps1”)
$PrintJobs = get-wmiobject -class “Win32_PrintJob” -namespace “root\CIMV2” -computername . | Where-Object {[System.Management.ManagementDateTimeConverter]::ToDateTime($_.TimeSubmitted) -lt $($(Get-Date).addMinutes(-60))}
foreach ($job in $PrintJobs) {
Write-Host “Canceling job $($job.JobId)”
$job.Delete()
}
Nice 🙂