Small powershell script to ping an IP address and send email

Hi,
I am after a small powershell script to carry a ping test on a server and send email when it is not reachable. I can use gmail account to send email.

Thanks
crazywolf2010Asked:
Who is Participating?
 
David Johnson, CD, MVPOwnerCommented:
0
 
David Johnson, CD, MVPOwnerCommented:
$servername = "s2k8r2e"
$from = "powershell@domain.com"
$to = "administrator@dowmain.com"
$r = Test-Connection -ComputerName $servername -Count 1 -Quiet -Source localhost -ErrorAction SilentlyContinue
if ( $r -eq $false){
	Write-Output ("Server $servername is Down")
	Send-MailMessage -From $from -To $to -Subject "Server Down" -Body "Server $servername is down"
	}
	else { 
	Write-Output ("Server $servername is UP") }

Open in new window

0
 
crazywolf2010Author Commented:
Hi,
I don't have mailx or an email routing in place at server.
Could you please modify this script to send an email using gmail account details.

Thanks
0
 
David Johnson, CD, MVPOwnerCommented:
which mail client do you have? outlook? or just a web client?
0
 
crazywolf2010Author Commented:
Hi,
It's on windows 2008 server so I would say web client only. There is an outgoing net connection from server.


Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.