Wednesday, 7 December 2016

POWERSHELL SCRIPT TEST CONNECTIVITY OF HOST or SERVER or INTERNET LINK and SEND MAIL TO ADMINISTRATOR



#### 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

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...