Average Mailbox Size Using Exchange PowerShell

PowerShell is now becoming more and more prevalent in Microsoft’s Exchange and Server software.     This scripting language is becoming a must know for Administrators and knowing this scripting can help get all kinds of useful information.  When I was an administrator for an Exchange system, it helped me to monitor the mailbox(s) and databases for their size, so that I could make plans for the future.

The script below gathers mailbox information and pulls the information together and shows it in the PowerShell window.


<———–Start Script———–>

# Retrieve the list of mailboxes from the specified mailbox database
$listOfMailboxes = Get-MailboxDatabase "Mailbox Database 1081629644" | Get-Mailbox
# Initialize the counter variables that we'll use
$mailboxCount = 0
$mailboxTotalItemCount = 0
$mailboxTotalSize = 0
$mailboxAverageSize = 0
$mailboxAverageItemCount = 0
# Start a loop that will count stats from individual mailboxes
foreach ($individualMailbox in $listOfMailboxes)
       # increment the mailbox count by 1
       # Get the name of the current mailbox so that we can...
       $individualMailboxName = $individualMailbox.Identity.DistinguishedName
       #... quickly and easily get stats from that mailbox
       $individualMailboxStats = Get-MailboxStatistics -Identity $individualMailbox
       # Get the size of the mailbox in MB and save it in a variable
       $individualMailboxSize = $individualMailboxStats.TotalItemSize.value.toMB()
       # Get the number of items in the mailbox and save it in a variable
       $individualMailboxItemCount = $individualMailboxStats.ItemCount
       # Add the size of this mailbox to a running total
       $mailboxTotalSize = $mailboxTotalSize + $individualMailboxSize
       # Add the number of items in this mailbox to a running total
       $mailboxTotalItemCount = $mailboxTotalItemCount + $individualMailboxItemCount
# Calculate the average mailbox size
$mailboxAverageSize = $mailboxTotalSize / $mailboxCount
# Calculate the average number of items per mailbox
$mailboxAverageItemCount = $mailboxTotalItemCount / $mailboxCount
# Display the results to the user
Write-Host "Total Number of Mailboxes in database: $mailboxCount"
Write-Host "Total Size of Mailboxes:               $mailboxTotalSize MB"
Write-Host "Total Items in Mailboxes:              $mailboxTotalItemCount"
Write-Host "-------------------"
Write-Host "Average Mailbox Size:                  $mailboxAverageSize MB"
Write-Host "Average Items per Mailbox:             $mailboxAverageItemCount"
<-----------End Script----------->

If everything ran correctly and you don’t see any errors, you will see the below displayed.

Total Number of Mailboxes in database: 320
Total Size of Mailboxes:               412270 MB
Total Items in Mailboxes:              14757
Average Mailbox Size:                  1288 MB
Average Items per Mailbox:             46.115625


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.