Powershell delete Paused – Spooling print jobs

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()

}

3 thoughts on “Powershell delete Paused – Spooling print jobs

  1. 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()
    }

  2. 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()
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.