Low Disk Space Alert Script

If backups should fail, or there is a mail storm…
How can I get alerted when the Exchange database transaction log disk is almost full?
It’s not a good day when the database dismounts because the TL disk fills up.
The info below is a script that will email you an alert when the TL disk gets under 10%

When a logical drive gets to 10% free (DiskSpaceThreshold) or 400MB left (LowDiskSpaceMinimum), the system log has an event ID 2013 generated.
These are defaults built into the OS.
If you want to change either of these settings, you have to create the registry key.
DiskSpaceThreshold
http://technet.microsoft.com/en-us/library/cc786996(WS.10).aspx
LowDiskSpaceMinimum
http://technet.microsoft.com/en-us/library/cc784049(WS.10).aspx

I assume you don’t have an enterprise program such as SCOM that monitors events… well then this powershell script is for you.
I created a task in task scheduler. I called it “LowDiskSpaceEventID2013”. I manually ran it to make sure it works properly, hence the last run time. (I had it send email to me while testing)

We probably want to change who it runs as, like a service account….


If I click on “Edit”, it has these properties

I put the script in the D:\WorkingFiles folder, the script is called SendMail.ps1. See the attached file.
The powershell script that can email someone internally.
If I point the server to itself when sending out, I get this error

The whole script looks like this

#SMTP server name
$smtpServer = "ex02.domain.local"
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
#Email structure
$msg.From = "no-reply@yourdomain.com"
$msg.ReplyTo = "no-reply@yourdomain.com"
$msg.To.Add("adminguy@yourdomain.com")
$msg.subject = "Low Disk Space on EX01"
$msg.body = "Event ID 2013 has been generated on EX01. Disk space is below 10% or 400MB"
#OR
#$msg.IsBodyHTML = $true
#$msg.body = get-content .moves.htm
#Sending email
$smtp.Send($msg)

I exported the task to an xml file.
Then I imported this task on the other exchange servers.
I copied the script and modified it for each server

The email message looks like this:

Advertisements

About Mike

owner of blog
This entry was posted in Exchange, PowerShell. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s