_Alfred

"In this the love of God was made manifest among us, that God sent his only Son into the world, so that we might live through him." - 1 John 4:9,10.

Powershell Script for Monitoring Availability of Network Hosts/Servers

By Alfred - Published: 2011-06-11

Here is my attempt to automate monitoring of available hosts/servers on my networks. I used the Test-Connection and Send-MailMessage cmdlets for sending an email with a list of hosts that are down as an attachment. It worked fine on Exchange 2007. However, it did not work for Exchange 2010 SP1. Received this error message: "Mailbox unavailable. The server response was: 5.7.1 Unable to relay." - You will have to create a new Relay Receive Connector and/or perform some permissions settings, as mentioned HERE or HERE and understand any security implications (take a look at: http://technet.microsoft.com/en-us/library/bb232021.aspx) to make it work with Exchange 2010 SP1.

$main_hosts = Get-Content "C:\Users\Admin\Documents\PoSh\Main_Hosts.txt"
$result = $TRUE

Foreach ($machine in $main_hosts) {
    $result = Test-Connection -ComputerName $machine -Quiet
    if ($result -eq $FALSE) {
        Add-Content -Path "C:\Users\Admin\Documents\PoSh\Hosts_Down.txt" -Value $machine
        $result = $TRUE
        $anydown = $TRUE
    }
}

if ($anydown -eq $TRUE) { 
     Send-MailMessage -SmtpServer "smtp.yourdomain.com" -to "admin@domain.com" -from "email@domain.com" 
          -Subject "Network Hosts Down" -Body "Please, examine attached file for non reachable hosts on the network."
          -Attachments "C:\Users\Admin\Documents\PoSh\Hosts_Down.txt" 
}
Clear-Content "C:\Users\Admin\Documents\PoSh\Hosts_Down.txt"

The following is the error obtained while trying to run the script and send the email through Exchange 2010 SP1:

Exchange 2010 - Unable To Relay Error