Tracking transaction log generation per hour

I’ve been working on the Exchange 2007 Mailbox Storage Calculator for my Exchange 2007 migration project.  The spreadsheet asks for the number of logs generated per hour so it can appropriately calculate the bandwidth needed for CCR and SCR log shipping.

Below is the script I wrote to do this for me.  Simply edit it to fit your Exchange server.  Since I have mulitple servers, I wrote one for each server, editing the name of the log file to match.  Then i created a batch file that runs each script for each Exchange server and created a scheduled task to re-run once per hour every hour.

FIlename: Count-Logs-EXCHSRVRNAME.ps1

function writetolog([string]$stringtowrite=”*”)
 {
     $datetime = (Get-Date).datetime
     Add-Content $logfile “$datetime : $stringtowrite”
 }

#the path to the log file you want to generate containing the count of
#transaction logs
$logfilename = “C:exchserver1-logcount.log”

#Make sure the count log file exists before attempting to write to it
if (Test-Path $logfilename) {Write-Host “Log file exists.”;$logfile = $logfilename} Else {Write-Host “Creating log file $logfilename”;$logfile = New-Item $logfilename -Type file}

#Path to the transaction logs for each storage group
$sg0path = “path to logs for SG0”
$sg1path = “path to logs for SG1”
$sg2path = “path to logs for SG2”
$sg3path = “path to logs for SG3”
$sg4path = “path to logs for SG4”

#Count the log files in each path, add them together and write that to the
#count log.
$sg0count = (get-childitem $sg0path).count
$sg1count = (get-childitem $sg1path).count
$sg2count = (get-childitem $sg2path).count
$sg3count = (get-childitem $sg3path).count
$sg4count = (get-childitem $sg4path).count
$date = get-date
writetolog ($sg0count + $sg1count + $sg2count + $sg3count + sg4count)

The count log file will contain data for each hour in the following format:

Tuesday, August 11, 2009 10:00:15 AM : 121
Tuesday, August 11, 2009 11:00:17 AM : 137

Simply import these logs into Excel, massage the data as needed to get an accurate count of how many log files are generated each day.  You’ll need to calculate the difference between each line of data to know how many logs were generated since the last count was taken since the script just counts the total number of logs in the directory.  You may need to add up the number for all the log files you generate if you’re generating one for each server you have.

Don’t forget to multiply by 5 before inputing the number into the Storage Calculator spreadsheet, though!  Exchange 2007 logs are 1MB in size while Exchange 2003 logs were 5MB in size!

Advertisements

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 )

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