0
ステータス=オフラインプリンタをフィルタリングしようとしていますが、その出力を電子メールの$ Bodyに送信しました。これまでの出力では、オンラインまたはオフラインのステータスに関係なく、すべてのプリンタとITが表示されます。あなたのdo...until
ループ内PowerShellディクショナリは、失敗したpingをフィルタリングします
Clear-Host
$printerip = @(
"192.168.141.104","192.168.141.250","192.168.141.251","192.168.141.53","192.168.141.157","192.168.141.167",
"192.168.141.115","192.168.141.116","192.168.142.25","192.168.142.23","192.168.1 44.80","192.168.144.57","192.168.150.51",
"192.168.150.50","192.168.150.40"
)
$printername = @(
"Shoreline Color",
"Dockside B/W",
"Shoreline B/W",
"Spinnaker",
"BA Ricoh Printer",
"BA Xerox Color",
"BA Lab 1",
"BA Lab 2",
"Dowagiac Ricoh",
"Dowagiac Xerox Color",
"Paw Paw Ricoh",
"Paw Paw Xerox Color",
"330 Finance 1",
"330 Finance 2",
"330 Copierr"
)
$status = @()
foreach($printer in $printerip){
if(Test-Connection $printer -Count 2 -Quiet){
$status += "Online"
}else{
$status += "Offline"
}}
$count = $printerip.Count
$counter = 0
$report = @()
do{
$report +=$status[$counter]+" - "+$printerip[$counter]+" - "+$printername[$counter]
$counter++
}until($counter -ge $count)
if($report -match 'offline'){$body = ("We should probably do something about this! `n `n") + $report | Out-String
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "Printer Test" -Body $body -SmtpServer "mail.domain.org"}