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