Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Using Regex HTML and If

$
0
0

Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4

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'

To = "admin@abc.com"

subject = "Ping Exchange $((get-date).ToShortDateString())"

SMTPServer = 'SMTPserver'

}

$report = ""

$ServerName = get-content “.\pingoutstatuslist.txt”

foreach ($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

$regex = [regex] "DOWN"

if ($regex.IsMatch($regexsubject)) {

Send-MailMessage @MessageParams -Body $report -bodyashtml -Priority high

}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles