Monitoring & Notifying Status of Exchange Services using Powershell

For those who have more then one exchange servers, i.e. Edge – Hub/Mailbox, you can use this script to monitor exchange services and if any of the services crashes and doesn’t come up this can help monitor and send notification via emails. Next week I will blog about a similar script that allows for remote monitoring of these services using Powershell and WMI.

So the process involves creating the script below, and then schedule it to run every hour using the Windows Scheduler. Once this is set, the service will run locally on the machine, query itself to see if any of the MSExch* services are paused or stopped. If it is it will use connect to the other mail server (edge uses hub or hub uses edge) and send a notification to the specified email address.

NOTE: You may have to create a service account to run this script in the scheduler or you may use your credential. This is entirely up to you.

OTHER IDEAS: This script can easily modified to fit anyone’s need. For example, one may modify the script to automatically start the services or send an SMS if needed. Other ideas can be integrated like try to start the services and keep count of the # of tries, if it fails 3 times then send out a notification. Use your imagination.

# Getting status of Exchange Services and look for anything that’s “stopped”
$ServiceStatus = get-service MSExch* | where-object {$_.Status -eq “stopped”}

# Convert Result to String
$ServiceStatusText = $ServiceStatus | fl | Out-String

# If $ServiceStatus <> $null then send notification
If ($ServiceStatus -ne $null)
###Exchange Server Values
$FromAddress = “Exchange-Alert@PNLAB.local
$ToAddress = “
$MessageSubject = “CRITICAL: An exchange service is has stopped”
$MessageBody = “One or more Exchange services has stopped running or crashed. Please check the server ASAP for possible issues`n”
$MessageBody = $MessageBody + $ServiceStatusText

$SendingServer = “msexch02.pnlab.local”

###Create the mail message and add the statistics text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody

###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer

# Else don’t do anything and exit



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s