Skip to main content
This site contains all sorts of collected goodies by Sean Wallbridge (SharePoint MVP) and the itgroove team and will continue to grow as times goes on.  itgroove - Victoria, BC SharePoint and Microsoft Technologies Business Consultants

Sean's SharePoint Ditty

Go Search
Home
  
Sean's SharePoint Ditty > Sean's Exchange PowerShell Reference > Send Exchange Mailbox stats (Display Name, Size and Item Count) as a scheduled Email  

Sean's Exchange PowerShell Reference: Send Exchange Mailbox stats (Display Name, Size and Item Count) as a scheduled Email

Title

Send Exchange Mailbox stats (Display Name, Size and Item Count) as a scheduled Email 

PowerShell Command

###Send mailbox statistics script

###First, the administrator must change the mail message values in this section
$FromAddress = MailboxReport@yourcompany.com
$ToAddress = administrator@yourcompany.com
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "e2k7.neilhobson.com"

###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)

### NOTE - this section is not for including in Powershell, this is for automating scheduling of the above script ###

Run the following from the scheduler to invoke the powershell and the above script:

PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\Bin\ExShell.psc1" -Command "./sendstats.ps1"

Functional Category

Mailbox Management; Reporting 

Reference Link

http://www.msexchange.org/articles_tutorials/exchange-server-2007/management-administration/getting-mailbox-statistics-exchange-2007.html 

Usefulness

Often Used 
Attachments
Created at 1/17/2009 11:55 AM  by Sean Wallbridge 
Last modified at 1/17/2009 11:55 AM  by Sean Wallbridge