# Setup E-mail Parameters
$smtpServer = "host.server.com"
$emailFrom = "from@address.com"
$emailTo = @('<to@address.com>')
$subject = "Top Recoverable Folder Size - $date"
$output = "c:\temp\output.csv"
#Import Exchange 2010 Module
Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue
#Setup Variables
[INT] $RQ = 0
[INT] $RW = 0
[INT] $DIQ = "30"
[INT] $DIW = "20"
$Path = "c:\temp\test.html"
#
#Exclusion
#Check if all Database Quota matches default
$Q = @(Get-mailboxdatabase | foreach {$_.recoverableitemsquota.value.tobytes()/1Gb})
foreach ($IQ in $Q) {
If ($IQ -notmatch "$DIQ")
{
write-host $IQ + "is not set to default settings"
$RQ++
}
}
If ($RQ -ge 1) { echo "default is not set for 1 or more mailboxes"}
#Check if all Database Quota matches warning default
$W = @(Get-mailboxdatabase | foreach {$_.RecoverableItemsWarningQuota.value.tobytes()/1Gb})
foreach ($IW in $W) {
If ($IW -notmatch "$DIW")
{
write-host $IW + "is not set to default settings"
$RW++
}
}
If ($RW -ge 1) { echo "storage default is not set for 1 or more mailboxes"}
$sort = @()
$output = "c:\temp\output.csv"
$mailboxes = Get-mailbox -resultsize unlimited
Foreach ($m in $mailboxes)
{
$size = Get-MailboxFolderStatistics $m -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"}
$sort = New-Object psobject -Property @{
mailbox = $m.alias
mailboxdn = $m.distinguishedname
recoversize = [math]::round($size.folderandsubfoldersize.tobytes() /1Gb, 3)
}
$sort | Export-Csv c:\temp\output.csv -notypeinformation -append
$sort =""
}
$output = "c:\temp\output.csv"
$mailboxesorted = import-csv $output | sort-Object {[INT]$_.recoversize} -Descending | select -First 10
$DiskDetailHTML += "<table>"
$DiskDetailHTML += "<tr><th>Mailbox</th><th>Mailbox Database</th><th>Mailbox ARC</th><th>Litigation Hold</th><th>Recoverablesize</th><th width=""400px"">Usage</th></tr>`n"
#loop through all mailboxes
Foreach ($mbx in $mailboxesorted)
{
$mbxinfo = get-mailbox $mbx.mailboxdn
#grab recoverable folder stats
$stat = Get-MailboxFolderStatistics $mbxinfo -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"}
#DB
$db = $mbxinfo.database
#ARC
$arcdb = $mbxinfo.archivedatabase
#LIT
$lit = $mbxinfo.litigationholdenabled
#recoveravle folder size to GB
$calcrsize = $stat.folderandsubfoldersize.tobytes()/1GB
$rsize = ($calcrsize).ToString("#.#######")
$alias = $mbxinfo.alias
#percentage
$calcpercent = ($rsize/$diq)
$percent = ($calcpercent).ToString("P") -replace '\s',''
$fpercent = (1-$calcpercent).ToString("P") -replace '\s',''
if ($percent -lt 0.01)
{
#
$DiskDetailHTML += "<TR>
<TD>$alias</TD>
<TD>$db</TD>
<TD>$arcdb</TD>
<TD>$lit</TD>
<TD>$rsize GB</TD>
<TD>
<table width=""100%"">
<tr>
<td width=""100%"" bgcolor=""green"" align=""Center"">$fpercent</td>
</tr>
</table>
</td></tr>`n"
} else {
$DiskDetailHTML += "<TR>
<TD>$alias</TD>
<TD>$db</TD>
<TD>$arcdb</TD>
<TD>$lit</TD>
<TD>$rsize GB</TD>
<TD>
<table width=""100%"">
<tr>
<td width=""$percent"" bgcolor=""Red"" align=""Center"">$percent</td>
<td width=""$fpercent"" bgcolor=""green"" align=""Center"">$fpercent</td>
</tr>
</table>
</td></tr>`n"
#
}
}
#Define static HTML
$HeaderHTML = @"
<html>
<head>
<style type='text/css'>
body { background-color:#DCDCDC;
}
table { border:1px solid gray;
font:normal 12px verdana, arial, helvetica, sans-serif;
border-collapse: collapse;
padding-left:30px;
padding-right:30px;
}
th { color:black;
text-align:left;
border: 1px solid black;
font:normal 16px verdana, arial, helvetica, sans-serif;
font-weight:bold;
background-color: #6495ED;
padding-left:6px;
padding-right:6px;
}
td { border: 1px solid black;
padding-left:6px;
padding-right:6px;
}
a.detail { cursor:pointer;
color:#1E90FF;
text-decoration:underline;
}
</style>
</head>
<body>
<h1>Recoverable Folder Size Report</h1>
<p>
"@
#Define Footer HTML
$FooterHTML = @"
</table>
</div>
</body>
</html>
"@
#Combine all the HTML fragments and save to a file
$HTML = $HeaderHTML + $DiskDetailHTML + $FooterHTML
$HTML | Out-File $Path
#>
Send-MailMessage -From $emailFrom -To $emailTo -Subject $Subject -Attachment $output -Body $HTML -BodyAsHtml -SmtpServer $smtpServer -EA Stop 2>> $errorlog
Recent Comments