$printer_status = Get-Printer -Name "my-printer" | select PrinterStatus
if ($printer_status.PrinterStatus -eq "TonerLow" -or $printer_status.PrinterStatus -eq "Normal" -or $printer_status.PrinterStatus -eq "PaperOut")
{
echo "0 Printer - OK - Printer is Online"
$counter = Get-Content C:\tmp\mycounter.txt
if ($counter -eq "1" )
{
"0" | Out-File C:\tmp\mycounter.txt
echo "counter reset"
}
}
if ($printer_status.PrinterStatus -eq "Offline" )
{
echo "2 Printer - Critical - Printer is Offline!!"
$counter = Get-Content C:\tmp\mycounter.txt
#echo $counter
if ($counter -eq "0" )
{
Restart-Service -Name Spooler -Force
"1" | Out-File C:\tmp\mycounter.txt
} else {
echo "already restarted!"
}
}

computer2know :: thank you for your visit :: have a nice day :: © 2024