Exchange 2007 Send Mailbox sizes with PowerShell

It could be verry usefull to receive a overview of all the mailbox sizes in your environments every day, week or month. You can see verry quickly when a users mailbox is growing to fast….The easiest way is to automate this, so i’ve made a PowerShell script to do this for me 🙂

—————————————————–
$body = Get-MailboxStatistics | sort-object -descending totalItemSize | ft DisplayName, @{expression={$_.totalitemsize.value.ToMB()};label=”Mailbox Size(MB)”}, itemcount, lastlogontime | out-string

$From = “administrator@e2k7.local”
$to = “m.swinkels@e2k7.local”
$server = “srv-ex01.e2k7.local”
$subject = “Mailbox overview – srv-ex01.e2k7.local”
$msg = new-object System.Net.Mail.MailMessage $From, $to, $subject, $body
$client = new-object System.Net.Mail.SmtpClient $Server
$Client.Send($msg)
—————————————————–

Copy this script into Notepad and save it as MailboxSizes.ps1. You can schedule this script to run every day, or every week using the following command:

C:\WINDOWS\system32\Windowspowershell\v1.0\powershell.exe -PSConsoleFile “D:\ExchSvr\Bin\exshell.psc1” C:\Scripts\MailboxSizes.ps1

C:\WINDOWS\system32\Windowspowershell\v1.0\powershell.exe
The path to Powershell.exe needed to run the script

-PSConsoleFile “D:\ExchSvr\Bin\exshell.psc1”
Loads the specified Windows PowerShell console file. To create a console file
(Change the path to the installation path of Exchange 2007 in your environment)

C:\Scripts\MailboxSizes.ps1
The path to the script.
(Change the path where you save the script)

When you try to run the script, you may receive an error “Client was not authenticated”.  You have to add the Exchange 2007 Server to an Relay Connector, so that this server can send e-mail without authentication. If you’ve done this and run the script, you’ll receive the following e-mail.

Â