咱們利用上篇文檔介紹的內容寫一個監控打印機應用:web
腳本內容以下:ide
$Printers="172.28.10.201","172.28.10.202"
foreach ($printer in $Printers){
$emailbody="
須要維護的打印機地址:
http://$printer/SSI/index.htm
請參照如下對照表:
172.28.10.201,(16F 打印區(移動事業部))
172.28.10.202,(16F 複印區)
$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 "打印機墨粉已不足5%請及時更換" -body "$emailbody" -Encoding ([System.Text.Encoding]::UTF8)
}
}url
郵件報警截圖htm