Hi
Thanks to people from this forum i managed to get a nice ping script (pings x number of servers) which i added to a schedule, but now i get allot of ping emails.
I wanted to know if it was possible to just send an email when one of the servers does not ping. I have tried using regex but it appears not to work probably because i am not using it correctly.
could any one help please
$MessageParams
= @{
= @{
From
= 'test@abc.com'
= 'test@abc.com'
To
= "admin@abc.com"
= "admin@abc.com"
subject
= "Ping Exchange $((get-date).ToShortDateString())"
= "Ping Exchange $((get-date).ToShortDateString())"
SMTPServer
= 'SMTPserver'
= 'SMTPserver'
}
$report
= ""
= ""
$ServerName
= get-content “.pingoutstatuslist.txt”
= get-content “.pingoutstatuslist.txt”
foreach
($Server in $ServerName)
($Server in $ServerName)
{
if (test-Connection -ComputerName $Server -Count 1 -Quiet )
{
$report += "<span
style=""color:blue"">$Server</span> <span
style=""color:green"">UP</span><br>" }
else
{
$report += "<span style=""color:red"">$Server</span>
<span
style=""color:red"">DOWN</span><br>" }
}
$report
$regexsubject
= $report
= $report
$regex
= [regex] "DOWN"
= [regex] "DOWN"
if
($regex.IsMatch($regexsubject)) {
($regex.IsMatch($regexsubject)) {
Send-MailMessage
@MessageParams -building $report -bodyashtml -Priority high
}