Tuesday, August 2, 2011

Script to Gauge Size of Exchange 2010 Log Files

I know this is supposed to be a Lync blog, but since Lync depends on Exchange, I thought this might be pertinent. We had an issue at our company where the backups for Exchange weren't working properly and the log files weren't truncating as designed. We just had no convenient means of visability into the status of the the log files or their back ups. as a quick, down and dirty way to get a status on where the log files were, I whipped up the below powershell script. The script just pulls the size of the log file directories, the idea being that if any grows above the baseline size (in our case that was 10 GB), it should be apparent to us that there's an issue with log truncation. It uses Sysinternal's Disk Updater, du.exe to pull the stats from the volumes. it also sends an email to the appropriate DG for action, and just for some sort of audit trail, it writes the stats to the application event log. See the text below for the script. Use it at your own risk. 
################################################################################
# Get-LogLength.ps1 [Version 1.0] - for server ServerNameHere
#
# This script will get the size of the mailbox database log directories for a
# down and dirty look at whether or not the log files are truncating as designed
# This script requires sysinternal's DU.EXE to be in the local directory
#
# Usage: Get-LogLength.ps1
# Author: Sean McNamara
# Date: July 26, 2011
################################################################################
$strBody = "Log Size for " + $env:computername + ":" + [Environment]::NewLine
$path = "DB1PathHere"
$result = & .\du -q $path
$strBody = $strBody + "DB1 " + "--  " + $result + [Environment]::NewLine
#
$path = "DB2PathHere"
$result = & .\du -q $path
$strBody = $strBody + "DB2 " + "--  " + $result + [Environment]::NewLine
#
$path = "DB3PathHere"
$result = & .\du -q $path
$strBody = $strBody + "DB3 " + "--  " + $result + [Environment]::NewLine
#
# add as many db lines as needed.

# This section will email the results to $To
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpServer = "smtprelay.yourcompany.com"
$SmtpClient.host = $SmtpServer
$From = "Youremail.address@yourcompany.com"
$To = "Youremail.address@yourcompany.com"
$Title = "Log File Report - " +  $env:computername
$SmtpClient.Send($from,$to,$title,$strBody) 

# This section creates an event log entry for audit purposes
write-eventlog -logname Application -source application -eventID 1111 -entrytype Information -message $strBody

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.