#### Create Excel with two column named IpAddress and LOCATION and list PUBLIC IP OF LINK and LOCATION in respective columns and save as CSV file ####
$servers = "E:\IPS.csv"
$csv = Import-CSV $servers
foreach($item in $csv){
$ip = $item.IpAddress
$location = $item.LOCATION
$smtpServer = "webmail.******.com"
$ping = new-object System.Net.NetworkInformation.Ping
$rslt = $ping.send($ip)
if ($rslt.status.tostring() –eq "Success") {
write-host ping worked on $server with $ip -ForegroundColor Green}
else {
$rslt1 = $ping.send($ip)
if ($rslt1.status.tostring() –eq "Success") {
write-host ping worked on $server with $ip -ForegroundColor Green}
else {
write-host ping failed on $server with $ip -ForegroundColor Red
# Send E-Mail
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "youmailID@domainname.com"
$msg.To.Add("youmailID@domainname.com")
$msg.Subject = "Warning: ping failed on $Location"
$msg.Body = "The Link $Location with ip adres $ip does not reply! "
$smtp.Send($msg)
}
}
}
$ping = $null
No comments:
Post a Comment