Solved

powershell alert when ping time drops

Posted on 2014-01-23
5
828 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 125 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 69

Accepted Solution

by:
Qlemo earned 375 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 69

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

740 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