Description

A powershell script by Neil Hobson at MSexchange.org

http://www.msexchange.org/articles_tutorials/exchange-server-2007/management-administration/getting-mailbox-statistics-exchange-2007.html can be configured to run as a recurring task to email the stats on a monthly basis.
With this stored in the root directory I’m running a scheduled task as follows

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1” -Command “./mailboxsizescript.ps1”

Source Code

###Send mailbox statistics script

###First, the administrator must change the mail message values in this section
$FromAddress = "fromname@domain.co.uk"
$ToAddress = "toname@domain.co.uk"
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "mail.domain.co.uk"

###Now get the stats and store in a text file
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}}, ItemCount > mailboxes.txt

###Create the mail message and add the statistics text file as an attachment
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress,
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("./mailboxes.txt")
$SMTPMessage.Attachments.Add($Attachment)

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


6 Spice ups

Thanks, i put this to run on my mailserver and it sends me a report weekly. I can take a glance at it and delete it when i’m done. Thanks for posting.

Glad it’s of use Kimberlin. I didn’t write it but thought it would be useful to other Spice Heads. I have it run monthly to see who are the big mailbox users.

Hello guys! Actually there is a a new widget that you can use to get various report and feedback for your Exchange mail server and you can add it to your dashboard. The widget is called " Microsoft Exhange Health " and it is really one of the best. Kindly yours, Spyros.

Hello guys! how would I go about adding a line to change the Scope to the above script. My Exchange environment has users that are in two separate domains on the same servers. such as: $AdminSessionADSettings.ViewEntireForest=$True

I’m afraid that I don’t know ph1llies05. I took the script from msexchange.org and included it here a benefit to Spiceworks users. When you refer to domain do you mean active directory domain or email domain? I have multiple email domains all going throught he same exchange server. Each user has one mailbox with the relevant mail domain pointing to it. The above script works fine in that scenario.

Im getting the following message after running the command straight in the shell: ------- cmdlet Get-MailboxStatistics at command pipeline position 1 Supply values for the following parameters: Identity: ------- Im on 2010, whcih is probably the problem. Any thoughts on how to run it on the whole DB, not just a single user? ####################### nevermind. The google machine told me that I can put a -server

If you get an error message about not being a relay server, you can easily add smtp authentication by adding this line beneath creating the smtp client $SMTPClient.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials Another thing I added to this was a list below of accounts not signed into exchange within the last 30 days to help identify in large companies redundant accounts. “Possible Old Accounts Not Logged in within 30 days:” >> mailboxes.txt Get-MailboxStatistics | where {$_.Lastlogontime -lt (get-date).AddDays(-30)} | Select displayName,LastLoggedOnUserAccount,LastLogonTime >> mailboxes.txt

AWESOME! Trying it now.