Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell alert when ping time drops

Posted on 2014-01-23
5
Medium Priority
?
878 Views
Last Modified: 2014-01-24
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"
}
0
Comment
Question by:cwstad2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Assisted Solution

by:Dale Harris
Dale Harris earned 500 total points
ID: 39803368
Using this snippet:
$Comp = "localhost"
$ping = get-wmiobject -Query "select * from win32_pingstatus where Address='$comp'"

You should be able to do a simple check against ping time:

if ($ping.responsetime -gt 1000)
{
//Do something
}

HTH,

Dale Harris
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1500 total points
ID: 39803570
"Ping time drops" - does that mean the time is greater or less than a limit? Your code fragment would trigger if the time needed for a ping is more than 1 second.
$Ping = Test-Connection -Count 1 -TTL 2000 -EA SilentlyContinue Server
if (!$Ping -or $Ping.ResponseTime -gt 1000)
{
  Send-MailMessage -To user@company.com -From "user@company.com" -SmtpServer smtp.domain.com -Subject "Ready"
}

Open in new window

which will also trigger if the target does not answer.
0
 
LVL 15

Author Comment

by:cwstad2
ID: 39804132
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
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39804172
'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.
0
 
LVL 15

Author Comment

by:cwstad2
ID: 39805835
thats great much appreciated
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question