Solved

powershell alert when ping time drops

Posted on 2014-01-23
5
792 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 68

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 68

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
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…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now