Exchange 2007 Mailbox Size Report – With Powershell
Mon, Nov 16, 2009This Powershell script generates a report of all mailboxes in an organization that are larger than 100MB. It sorts them from largest to smallest and generates a pretty HTML report to send. Using variations of this script you could set it to only generate the first 10 “big hitters”, ignore the Custom Attribute fields (which in my situation show which company the box belongs to), or make any other change that would customize it for your environment. If you would like any help with using this script, feel free to let me know in the comments.
I run this script once weekly using scheduled tasks.
Also, a huge thanks to Glen Scales at Glen’s Exchange Dev Blog. You will find aspects of his code in mine, and his website gave me the base for a lot of the scripts I use.
$message = new-object System.Net.Mail.MailMessage("[email protected]", "[email protected]")<br />
$message.IsBodyHtml = $True<br />
$message.Subject = "Automated E-Mail Quota Report"<br />
$smtp = new-object Net.Mail.SmtpClient("172.16.1.100")
$mbcombCollection = @()<br />
Get-Mailbox -ResultSize Unlimited | foreach-object{<br />
$mbstatis = get-mailboxstatistics $_.identity<br />
$TotalSizeMB = $mbstatis.TotalItemSize.Value.ToMB()
$mbcomb = "" | select DisplayName, TotalItemSizeMB, QuotaStatus, Itemcount, Email, CompanyName
$mbcomb.DisplayName = $_.DisplayName<br />
$mbcomb.TotalItemSizeMB = $TotalSizeMB<br />
$mbcomb.Itemcount = $mbstatis.ItemCount<br />
$mbcomb.QuotaStatus = $mbstatis.StorageLimitStatus<br />
$mbcomb.Email = $_.PrimarySmtpAddress<br />
$mbcomb.CompanyName = $_.CustomAttribute1<br />
$mbcombCollection += $mbcomb<br />
}
``This Powershell script generates a report of all mailboxes in an organization that are larger than 100MB. It sorts them from largest to smallest and generates a pretty HTML report to send. Using variations of this script you could set it to only generate the first 10 “big hitters”, ignore the Custom Attribute fields (which in my situation show which company the box belongs to), or make any other change that would customize it for your environment. If you would like any help with using this script, feel free to let me know in the comments.
I run this script once weekly using scheduled tasks.
Also, a huge thanks to Glen Scales at Glen’s Exchange Dev Blog. You will find aspects of his code in mine, and his website gave me the base for a lot of the scripts I use.
$message = new-object System.Net.Mail.MailMessage("[email protected]", "[email protected]")<br />
$message.IsBodyHtml = $True<br />
$message.Subject = "Automated E-Mail Quota Report"<br />
$smtp = new-object Net.Mail.SmtpClient("172.16.1.100")
$mbcombCollection = @()<br />
Get-Mailbox -ResultSize Unlimited | foreach-object{<br />
$mbstatis = get-mailboxstatistics $_.identity<br />
$TotalSizeMB = $mbstatis.TotalItemSize.Value.ToMB()
$mbcomb = "" | select DisplayName, TotalItemSizeMB, QuotaStatus, Itemcount, Email, CompanyName
$mbcomb.DisplayName = $_.DisplayName<br />
$mbcomb.TotalItemSizeMB = $TotalSizeMB<br />
$mbcomb.Itemcount = $mbstatis.ItemCount<br />
$mbcomb.QuotaStatus = $mbstatis.StorageLimitStatus<br />
$mbcomb.Email = $_.PrimarySmtpAddress<br />
$mbcomb.CompanyName = $_.CustomAttribute1<br />
$mbcombCollection += $mbcomb<br />
}
``
$message.Body = $body<br />
$smtp.Send($message)