none
Delete PrintJob RRS feed

  • Question

  • Hi Folks,
       I have wrote PowerShell script if print job hung for over 1 minute, will delete the job.
    If I run manually works fine. Question would be how can continuously run this script so it will find and delete job or is there any other method you folks can think?..

    thanks for  your help in advance.

    #*******************************************************************************************************
    [CmdletBinding()]
    Param()
    
    $printServer            = "Printserver"
    
    $1MinuteEarly           = New-TimeSpan -Minutes +1
    $AddingMinute           = (get-date) - $1MinuteEarly 
    
    
    #
    
    #Getting All Printers from Print Server Variable $printServer matching only ABC QUEUE
    $AllPrinters            = Get-Printer -computername $PrintServer | Where-object NAME -Like "*ABC*"
    Write-Host 'Found Printers Name "$AllPrinters: " '$AllPrinters''
    
    
    #$PrinterJobsTime = get-printer -computername $printServer |get-printjob |Where-Object PrinterName -LIKE "*ABC*" | Where-Object {$_.timesubmitted -lt $AddingMinute -and $_.JobStatus -notmatch "Deleting, Spooling"}   #SELECT submittedTime
    
    Foreach($Printer in $AllPrinters){
    
            Write-Host 'PrintQueue: " '$Printer' '
            
              $PrinterJobsTime = get-printjob $Printer | Where-Object {$_.submittedTime -lt $AddingMinute} #-and $_.JobStatus -notmatch "Deleting, Spooling"}   #SELECT submittedTime
             #$PrinterJobsTime = get-printjob $Printer | Where-Object {$_.submittedTime -lt $AddingMinute -and $_.JobStatus -notmatch "Deleting, Spooling"} 
    
                IF($PrinterJobsTime)
                  {
                    
                    Write-Host 'Found Job hung for 2 Minutes: '$PrinterJobsTime' '
    
                    ForEach($job in $PrinterJobsTime) 
    
                        {
                        Try 
                            {
                               # Remove-PrintJob $job
                                Write-Host "Delete Print Job '$PrinterJobsTime' completed"
                            }
                        Catch
                            {
                                Write-Host "Unable to Delete Print Job '$PrinterJobsTime', Error!!"
                            }
    
                        }
                }
    
                Else{$PrinterJobsTime -eq "null" 
                  
                    Write-Host "Didn't find any Job hung for 2 Minutes: $Printer"
                }
    
    
    
              
        }
    


    • Moved by Bill_Stewart Friday, March 15, 2019 3:10 PM User should not be doing this
    Thursday, December 13, 2018 7:21 PM

All replies

  • How do you know if a job is hung or if it is just a very big job?  How can you tell if a job is waiting for someone to add paper or toner to the printer?

    In Windows the spooler design is that users mange their own jobs.  If they see a job is hung they just delete it.

    The best thing is to scan for "error printing" and remove jobs in error with a message to the user. Even that has issues of management.

    To learn how to best mange spoolers post your issue in the Windows Printing forum.


    \_(ツ)_/

    Thursday, December 13, 2018 7:49 PM
  • I am checking with "submittedTime" from job and if it is over a minute then killing it.
    Thursday, December 13, 2018 8:00 PM