Ultimate Printer: Print Queue, Print Job, Error Stuck, Status Monitor repair report WMI HTML Email
Ultimate Printer: Print Queue, Print Job, Error Stuck, Status Monitor repair report WMI HTML Email
Run this script every few minutes and your worries with stuck printer jobs will be virtually over.
The script also generates a web page the Field techs can use to see if a printer is out of paper
in error status, etc (Status types below). Any actions the script takes are recorded in the log
including all the information you will every need about the print job.
Things to do to make this work:
Edit webfile directory to be your web directory of choice
Edit logfile directory
Edit myservers list to reflect the servers in your company
Source
#Detect Clean Log Email printers and jobs.
#files
$webfile = "c:\svr\www\printers\index.php"
$mylog = ("c:\svr\logs\scripts\monitorprinterqueues_" + (Get-Date).month + (Get-Date).day + (Get-Date).year + ".log")
if ((Test-Path $mylog ) -ne $true) {#check for new log
$myheader = "datetime*owner*jobstatus*queuestatus*totalpages*size*server*queue*document"
$myheader| out-file -FilePath $mylog -append -noclobber
}#check for new log
function mystatus ($thisstatus) {
switch ($thisstatus) {
"0" { $mytext = "Ok" }
"1" { $mytext = "Other" }
"2" { $mytext = "No Error" }
"3" { $mytext = "Low Paper" }
"4" { $mytext = "No Paper" }
"5" { $mytext = "Low Toner" }
"6" { $mytext = "No Toner" }
"7" { $mytext = "Door Open" }
"8" { $mytext = "Jammed" }
"9" { $mytext = "Service Requested" }
"10" { $mytext = "Output Bin Full" }
"11" { $mytext = "Paper Problem" }
"12" { $mytext = "Cannot Print Page" }
"13" { $mytext = "User Intervention Required" }
"14" { $mytext = "Out of Memory" }
"15" { $mytext = "Server Unknown" }
default {$mytext = "Error (D)" }
}
return ($mytext)
}
clear
$myservers = @()
$myservers = ("printserver1.domain.local","printserver2.domain.local","printserver3.domain.local","printserver4.domain.local")
#exporttoweb
Remove-Item ($webfile)
$head = "<style>"
$head = $head + "BODY{background-color:#9FAEB5;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#999999}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$head = $head + "</style>"
foreach ($thisserver in $myservers) {
$prnstats = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $thisserver
$printserver = get-wmiobject "Win32_PrintJob" -computername $thisserver | where { ($_.jobstatus -ne $null) -and ($_.jobstatus -ne "") -and ($_.jobstatus -ne "Printing") -and ($_.jobstatus -ne "Spooling") -and ($_.jobstatus -ne "Spooling | Printing") }
if ((Test-Path -Path $webfile) -ne $true) {#writehead top
$prnstats | select Name, Systemname, @{Name="DetectedErrorState";Expression={mystatus $_.DetectedErrorState }}, Location | ConvertTo-HTML -head $head -body "<H2>Printer Status Site</H2>" | Out-File $webfile
} else {
$prnstats | select Name, Systemname, @{Name="DetectedErrorState";Expression={mystatus $_.DetectedErrorState }}, Location | ConvertTo-HTML | Out-File $webfile -Append
}
foreach ($printjob in $printserver) {
if (($printjob.Jobstatus -ne $null) -and ($printjob.Jobstatus -ne "")){
switch ($printjob.Jobstatus) {
default {
$prn = $prnstats | where { $_.name -eq ("" + $printjob.Name.split(',')[0]) }
$thisstr = "" + $printjob.TimeSubmitted + "*" + $printjob.Owner + "*" + $printjob.JobStatus + "*" + (mystatus $prn.DetectedErrorState) + "*" + $printjob.TotalPages + "*" + $printjob.Size + "*" + $thisserver + "*" + $printjob.Name + "*" + $printjob.Document
$thisstr | out-file -FilePath $mylog -append -noclobber
$printjob.Delete()
}#end default
}#end switch
}#end if
#$printjob = $null
}#jobs
$printserver = $null
#$printjob = $null
}#servers