Mailbox Stats Mailed Exchange 2010

The goal of this article is to create a mailbox.txt file that contains mailbox statistics about your exchange users AND to have it mailed to you everyday at say, 5:00pm.

This article is specific for Exchange 2010, but it can be used on 2007, just modify the path to Exchange installation folder by removing the “v14” folder.

You will be creating two files, both reside in the “bin” folder of exchange, by that I mean for a standard installation of Exchange 2010, it would be the following folder:
C:\Program Files\Microsoft\Exchange Server\v14\bin

First, create a file called SendStats.ps1 that has the following two lines of code and three comment lines (which begin with ###)

###Send mailbox statistics script###
###Get the stats and store in a text file called mailboxes.txt###
Get-MailboxStatistics -database "Exchange Mailbox Database"| Sort-Object DisplayName | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount > mailboxes.txt

###Create the mail message and add the mailboxes.txt text file as an attachment###
Send-MailMessage –From –To –Subject "Mailbox Size Report" –Body "Attached is the current list of mailbox sizes." -Attachment "Mailboxes.txt" –SmtpServer localhost

You will need to modify the -database “Exchange Mailbox Database” to the actual name of your database and you will need to modify the from and to addresses to a valid email address for your system.
I found that exchange 2010 likes ‘localhost’, but exchange 2007 likes the dns name of the server itself, as in ‘server1.addomain.local’

Then, create another file called MBStats.bat which contains two lines of code:

cd "C:\Program Files\Microsoft\Exchange Server\v14\Bin"
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\v14\Bin\ExShell.psc1" -Command "sendstats.ps1"

The nice thing about this batch file is that it easily allows you to make the scheduled task without a lot of command line arguments  (and testing the script from a cmd prompt is easy too)

Like I said above, both of these files are stored in the “bin” folder of exchange.

Finally, go into the Scheduled Tasks of Windows 2008 R2 and create a scheduled task to run every day at 5pm, whether user is logged on or not.

You can just type in the batch file name, you won’t need to point to the entire path location because the Exchange “bin” folder is already in the PATH variable.


Author: Mike

owner of blog

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 )

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 )

Connecting to %s