Exchange 2010 – Get-MailboxDatabaseStatistics (your customization)

The function Get-MailboxDatabaseStatistics has been created due to a reporting purpose. I was focused mainly on script output and customization. It means that the most part of script code is related to the output and its attributes. Well it would be quite easy to modify the output attributes based on your needs.

Script prerequisites

  • Exchange Server 2010
  • Exchange Management Shell run-space
  • Organization Management (RBAC)

Script inputs

The function requires one of these inputs: DatabaseName, ServerName, AllDatabases. It means that we can call the function for example like:

Get-MailboxDatabaseStatistics -DatabaseName mbx11

Get-MailboxDatabaseStatistics -DatabaseName mbx11,mbx12

Get-MailboxDatabaseStatistics -DatabaseName (Get-MailboxDatabase|?{$_.Server -like "*exch10*"})

Get-MailboxDatabaseStatistics -ServerName exch10ser01

Get-MailboxDatabaseStatistics -AllDatabases

Database queries (code)

The function expects database name/names declared via input parameters. After input validation process, the function can process particular database name in a loop. The loop is uses for the following queries:

  • $query1 = Get-MailboxDatabase -Identity $db -Status
  • $query2 = Get-Mailbox -Database $db
  • $query3 = $query2 |%{if($_.Identity -ne $null){Get-MailboxStatistics -identity $_.identity}}

As can be seen above, here is the first thing for consideration/customization. Because the script processing time depends primarily on amount and severity of particular query. So the processing time can be decreased by query optimization (e.g. omit  Get-Mailbox etc.).

Output attributes (code)

The loop fills query variables ($query1, $query2, $query3) and those variables are used for declaration of attributes into output brick.  Due to this reason the brick can contain original values as same as a variation of values from all queries at once. Attributes are added into the brick through simple function addResultAttribute:

function addResultAttribute ($propertyName,$propertyValue){
$result | add-member -Type NoteProperty -name $propertyname -value $propertyValue

Just for example we can create attribute DatabaseName by using query1 (Get-MailboxDatabase -Status) and its parameter Name:

  • DatabaseName : DB01
addResultAttribute DatabaseName $query1.Name

Another example is attribute  RecipientTypeStatus which keeps amount of mailboxes based on  RecipientTypeDetails:

  • RecipientTypeStatus: {158-UserMailbox, 36-SharedMailbox, 1-DiscoveryMailbox, 3-ArbitrationMailbox}
addResultAttribute RecipientTypeStatus (($query2|Group-Object -Property RecipientTypeDetails|%{$_.Count,$_.Name -join ("-")}) -join (",")).ToString()

Feel free to modify brick attributes. The function contains only attributes regarding my scenario.

Scrip output

The output is brick wall as collection. It contains the brick with declared attributes for each database which was processed by the function. So it can looks like:

DatabaseName                     : DB01
DatabaseSize                     : 171 GB (183,619,878,912 bytes)
AvailableNewMailboxSpace         : 12.3 GB (13,204,750,336 bytes)
CircularLoggingEnabled           : False
LogFolderPath                    : E:\DB01
EdbFilePath                      : E:\DB01\DB01.edb
IssueWarningQuota                : 2.876 GB (3,088,056,320 bytes)
ProhibitSendQuota                : 3 GB (3,221,225,472 bytes)
ProhibitSendReceiveQuota         : 3.276 GB (3,517,972,480 bytes)
LastFullBackup                   : 5.4.2013 15:01:15
LastIncrementalBackup            : 7.4.2013 15:01:13
DatabaseCopiesCount              : 2
DatabaseCopiesServer             : {exch10Ser01, exch10Ser01}
TotalMailboxCount                : 198
RecipientTypeStatus              : {158-UserMailbox, 36-SharedMailbox, 1-DiscoveryMailbox, 3-ArbitrationMailbox}
MailboxWithDatabaseQuotaCount    : 189
ArchiveMailboxCount              : 130
SoftDeletedMailboxCount          : 
DisconectedMailboxCount          : 4
MailboxTotalItemSizeSumMB        : 138996
MailboxTotalDeletedItemSizeSumMB : 4931
MailboxTotalSizeSumMB            : 143927
MailboxTotalItemCount            : 1426074
Top3LargestMailboxSize           : {2.935 GB (3,151,719,330 bytes), 2.904 GB (3,118,361,061 bytes), 2.897 GB (3,110,582,421 bytes)}
Top3LargestMailboxName           : {Kasaj Filip, Salon Zbynek, Namjman Lukas}
MailboxLimitStatus               : {187-BelowLimit, 6-NoChecking, 4-IssueWarning}

Of course that we can use the function also:

[PS] C:\> $rep = Get-MailboxDatabaseStatistics -DatabaseName db01
[PS] C:\> $rep.MailboxTotalDeletedItemSizeSumMB

[PS] C:\> $rep2 = Get-MailboxDatabaseStatistics -DatabaseName db01,db02
[PS] C:\> $rep2 | fl RecipientTypeStatus
RecipientTypeStatus : {158-UserMailbox, 36-SharedMailbox, 1-DiscoveryMailbox, 3-ArbitrationMailbox}
RecipientTypeStatus : {151-UserMailbox, 52-SharedMailbox}

[PS] C:\> Get-MailboxDatabaseStatistics -AllDatabases | Export-Csv -Delimiter "," -Encoding unicode -Path "C:rep.txt"

How to load the function

  • Save function as ps1 file.
  • Import the file into Exchange Management Shell.
  • That’s it.

07-04-2013 19-45-27Download: 



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s