Using script to monitor the application of toner in printer
We use the content introduced in the previous document to write a monitoring printer application:
The script reads as follows:
$Printers= "172.28.10.201", "172.28.10.202"
Foreach ($printer in $Printers) {
$emailbody= "
Printer address to be maintained:
Http://$printer/SSI/index.htm
Please refer to the following comparison table:
172.28.10.201, (16F print area (Mobile Division))
172.28.10.202, (16F copy area)
$url=invoke-webrequest "http://$printer/SSI/index.htm"
$cartridge= ($url.ALLelements.innertext | findstr "%") [1]
$stringnumber= (($cartridge.replace ("", "). Replace ("% ","). Replace ("Black Cartridge", "). Replace (" * ",")
Echo $stringnumber
$intnumber= [int] $stringnumber
If ($intnumber-le 5) {
Echo $printer
Send-MailMessage-From it@contoso.com-To lixs@contoso.com-SmtpServer mail.contoso.com-Subject "Printer toner less than 5% Please change in time"-body "$emailbody"-Encoding ([System.Text.Encoding]:: UTF8)
}
}
Screenshot of email alarm