PowerShell: list mailbox database statistics (quota, mailbox count and size) – version 2

This script now includes reading the quota settings per mailbox database. There is no need to specify the input, as it automatically iterates through all mailbox databases in the organization (as long as your user account has sufficient permissions to see them). Then it starts building up a table object and filling rows with the results. This works pretty well, since you can use the table for sorting, displaying and usage in other scripts.

After you execute the below script, you will get a $table object containing all the data. To filter and sort this, use for example:

$table | where-object {$_.MailboxCount -gt 1} | sort “MailboxCount” | ft -autosize

The above statements filters and keeps all rows where the MailboxCount column is greather than 1, then sorts on that column and formats the table as output.

Another example is:

$table | where-object {$_.IssueWarningQuotaMB -gt 300 -and $_.IssueWarningQuotaMB -lt 1000} | sort “MailboxCount” | ft -autosize

The script to generate $table:

$table = New-Object system.Data.DataTable “$myTable”
$col1 = New-Object system.Data.DataColumn Identity,([string])
$col2 = New-Object system.Data.DataColumn MailboxCount,([decimal])
$col3 = New-Object system.Data.DataColumn SizeMB,([decimal])
$col4 = New-Object system.Data.DataColumn ProhibitSendQuotaMB,([decimal])
$col5 = New-Object system.Data.DataColumn ProhibitSendReceiveQuotaMB,([decimal])
$col6 = New-Object system.Data.DataColumn IssueWarningQuotaMB,([decimal])
$dbs = Get-MailboxDatabase
foreach ($db in $dbs)
$dbstats = Get-MailboxStatistics -database $db
$totaldbsize = 0
$totalmbcount = 0
foreach ($dbstat in $dbstats)
$totalmbcount = $totalmbcount + 1
$totaldbsize = $totaldbsize + $dbstat.TotalItemSize.Value.ToMB()
$row = $table.NewRow()
$row.Identity = $db.Identity
$row.MailboxCount = $totalmbcount
$row.SizeMB = $totaldbsize
$row.ProhibitSendQuotaMB = $db.ProhibitSendQuota.Value.ToMB()
$row.ProhibitSendReceiveQuotaMB = $db.ProhibitSendReceiveQuota.Value.ToMB()
$row.IssueWarningQuotaMB = $db.IssueWarningQuota.Value.ToMB()
$table | sort “identity” | ft -AutoSize

Geschreven door:

Arnout van der Vorst

Arnout van der Vorst is Identity Management Architect bij Tools4ever en al ruim 10 jaar in dienst. Arnout legt zich als Architect toe op het bedenken en ontwikkelen van nieuwe features, oplossingen en diensten van Tools4ever die aansluiten op de vraag uit de markt. Arnout studeerde Hogere Informatica aan de Hogeschool van Utrecht.