Link to home
Start Free TrialLog in
Avatar of cwstad2
cwstad2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

powershell alert when ping time drops

Hi guys, we have a switching mechanism on our servers whereby the networks switch speeds varying on location. These times can vary but is it possible to email when the ping time drops, which would indicate the network switch. I have the following script below but doesnt seem to work correctly. also is it possible to loop until the condition is met

thanks


$ping = ping server
if ($ping -gt 1000)
{
Send-MailMessage -To user@company.com -From "user@company.com" -SmtpServer smtp.domain.com -Subject "Ready"
}
SOLUTION
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cwstad2

ASKER

Hi guys, when its on one network it's ~ 800 ms and then on VPN  < 100.  Qlemo i changed it to less than 100 but it doesnt loop until this condition is met. can this contiunually loop until that condition is met?

thanks
'f course it is, but you didn't say that yet ;-)
while (!($Ping = Test-Connection -Count 1 -TTL 2000 -EA SilentlyContinue Server)
   -or $Ping.ResponseTime -gt 100)
{
  Start-Sleep -seconds 60
}
Send-MailMessage -To user@company.com -From "user@company.com" -SmtpServer smtp.domain.com -Subject "Ready"

Open in new window

This will scan once every minute, until ping time is less or equal 100.
Avatar of cwstad2

ASKER

thats great much appreciated