Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Small powershell script to ping an IP address and send email

Posted on 2012-09-11
5
Medium Priority
?
1,602 Views
Last Modified: 2012-10-09
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
0
Comment
Question by:crazywolf2010
  • 3
  • 2
5 Comments
 
LVL 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 2000 total points
ID: 38389357
$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
 

Author Comment

by:crazywolf2010
ID: 38390044
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
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 38390053
which mail client do you have? outlook? or just a web client?
0
 

Author Comment

by:crazywolf2010
ID: 38390084
Hi,
It's on windows 2008 server so I would say web client only. There is an outgoing net connection from server.


Thanks
0
 
LVL 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 38390173
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

810 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