Categorized Mailbox Size Report

We're working with a few groups to implement mailbox limits. To assist their users, I've been working on a report that breaks down the users into a few basic size limits. This function takes an array of IDs (Distinguished name field required) and returns a fairly basic HTML report back.

I am using the Quest AR Powershell cmdlet to read a group membership for my source data.

For example:

 
$SourceGrp = "Finance Department"
#Read in group membership.
$mbxDLGroup = Get-qadgroupmember -identity $sourcegrp -indirect -type user -sizelimit 0 -DontUseDefaultIncludedProperties -includedproperties dn |  select @{Name="distinguishedname"; Expression={$_.dn}}, displayname

$mbxreport = ".\"+$sourcegrp.toupper() + "-MailboxSummary.html"
Create-MailboxSizeReport  -MBXGroup $mbxDLGroup | Out-File $mbxReport

Example Report:

Mailbox Summary by Size

07/08/2011 11:29:55
1 Objects found

--------------------------------------------------------------------------------
0 - 250mb: 1
251 - 500mb: 0
501 - 1023mb: 0
1024 - 2048mb: 0
2gb+:0

Mailbox Details

0 to 250MB

DisplayName MailboxSize_MB
Eric Woodford 126

 
function Create-MailboxSizeReport {
        param(
        [Parameter(Position=1,Mandatory=$true,ValueFromPipelineByPropertyName=$true)] $MBXGroup
        )
       
        $MailboxReport = "<h2>Mailbox Summary by Size</h2>"
        $MailboxReport += Get-Date
        $MailboxReport += "<br />"
       
        #Mailbox arrays
        $s250 = @()
        $s500 =@()
        $s1024 = @()
        $s2048 = @()
        $larger = @()

        $mbxCount = $MbxGroup.count    
        $index = 0
        foreach ($MbxObj in $MBXGroup) {
                $pcomplete = [int](($index / $mbxCount) * 100)
                $pstatus = "Percent Processed:" +$Pcomplete
                Write-Progress -activity "Getting Mailbox Sizes" -status $pstatus -PercentComplete (($index / $mbxCount) * 100)
                $m = get-mailboxstatistics $mbxobj.distinguishedname | select displayname, totalitemsize
                if ($m.totalitemsize -le 250MB) {$s250 += $m}
                elseif ($m.totalitemsize -le 500MB) {$s500 += $m}
                elseif ($m.totalitemsize -le 1GB) {$s1024 += $m}
                elseif ($m.totalitemsize -le 2GB) {$s2048 += $m}
                else {$larger += $m}
                $index ++
        }

        $i = 0

        $mbxCount = $s250.count + $s500.count + $s1024.count + $s2048.count + $larger.count
        $MailboxReport += $mbxCount.tostring() + " Objects found <br />"
        $MailboxReport += "<hr />"

        $MailboxReport += "`t<b>0 - 250mb:</b> " + $s250.count +"<br />"
        $MailboxReport += "`t<b>251 - 500mb:</b> " + $s500.count +"<br />"
        $MailboxReport += "`t<b>501 - 1023mb:</b> " + $s1024.count +"<br />"
        $MailboxReport += "`t<b>1024 - 2048mb:</b> " + $s2048.count +"<br />"
        $MailboxReport += "`t<b>2gb+:</b>" + $larger.count +"<br />"

        $MailboxReport += "<br /><h2>Mailbox Details</h2>"
        $MailboxReport += "<h4>0 to 250MB</h4>"
        $MailboxReport += $s250 | select Displayname, @{Name="MailboxSize_MB"; Expression={$_.TotalItemSize.Value.ToMB()}} | sort MailboxSize_MB | ConvertTo-Html
        $MailboxReport += "<h4>251 to 500MB</h4>"
        $MailboxReport += $s500 | select Displayname, @{Name="MailboxSize_MB"; Expression={$_.TotalItemSize.Value.ToMB()}} | sort MailboxSize_MB | ConvertTo-Html
        $MailboxReport += "<h4>501 to 1024MB</h4>"
        $MailboxReport += $s1024 | select Displayname, @{Name="MailboxSize_MB"; Expression={$_.TotalItemSize.Value.ToMB()}} | sort MailboxSize_MB| ConvertTo-Html
        $MailboxReport += "<h4>1025 to 2048MB</h4>"
        $MailboxReport += $s2048 | select Displayname, @{Name="MailboxSize_MB"; Expression={$_.TotalItemSize.Value.ToMB()}} | sort MailboxSize_MB| ConvertTo-Html
        $MailboxReport += "<h4>2GB+</h4>"
        $MailboxReport += $larger | select Displayname, @{Name="MailboxSize_MB"; Expression={$_.TotalItemSize.Value.ToMB()}} | sort MailboxSize_MB | ConvertTo-Html
        return $MailboxReport
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.