Large Mailboxes$MBLimit=2048
$MailboxDatabases=Get-MailboxDatabase
ForEach ($DB in $MailboxDatabases)
{
$Mailboxes+=Get-MailboxStatistics -Database $DB.Name
}
$LargMailboxes= $Mailboxes | where {$_.TotalItemSize.Value.ToMB() -gt $MBLimit } | sort TotalItemSize | select DisplayName, TotalItemSize
$LargMailboxes | select DisplayName, TotalItemSize
Large Mailboxes Email
$MBLimit=2048
Function check-even ($num) {[bool]!($num%2)}
$smtpServer = "mail.blah.com"
$To = "Kevin Curran <kcurran@blah.com>"
$From = "AD Reporting <ADReporting@blah.com>"
$PreMessage = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:MidnightBlue; color:Yellow}
TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}
TR.D0 TD {background-color: White; color: black;}
TR.D1 TD {background-color: LawnGreen; color: black;}
</style>
</head><body>
“@
$PostMessage += "This script was run by " + $env:username + " on " + $env:COMPUTERNAME
$PostMessage += "<br>ScriptName: $($MyInvocation.MyCommand) "
$PostMessage += "<br>Script path: $(Split-Path -Parent $MyInvocation.MyCommand.Path)"
$PostMessage += "</body></html>"
$MailboxDatabases=Get-MailboxDatabase -status
ForEach ($DB in $MailboxDatabases)
{
$Mailboxes+=Get-MailboxStatistics -Database $DB.Name
}
$LargMailboxes= $Mailboxes | where {$_.TotalItemSize.Value.ToMB() -gt $MBLimit } | sort TotalItemSize | select DisplayName, TotalItemSize
$Mailboxes=$null
$Message= $MailboxDatabases | sort -Property Name | ConvertTo-Html -Property Name, DatabaseSize -PreContent `
"<H2>Mailbox Database Size</H2>" | ForEach-Object {$_}
$Message+= $LargMailboxes | sort -Descending -Property TotalItemSize | ConvertTo-Html -Property DisplayName, TotalItemSize -PreContent `
"<H2>Large Mailbox List</H2> Mailboxes larger than 2 GB." | ForEach-Object {$_}
$ModifiedHTML=ForEach ($line in $Message)
{
$counter++
if (check-even $counter)
{$line.replace('<tr><td>','<tr class="d0"><td>')}
Else
{$line.replace('<tr><td>','<tr class="d1"><td>')}
}
$html = $PreMessage + $($ModifiedHTML | out-string) + $PostMessage
Send-MailMessage -From $From -To $To -SmtpServer $smtpServer `
-Subject "Large Mailbox List" -BodyasHTML $HTML
Blah blah blah
|