Solved

powershell alert when ping time drops

Posted on 2014-01-23
5
821 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 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