Exchange Powershell "Get Mailbox Averages"



I like this one, so I needed to add it to the posts for future reference.

Scott Lowe originally posted at Techrepublic here.

http://www.techrepublic.com/blog/networking/powershell-script-get-mailbox-averages/5045?tag=nl.e102




# 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
$mailboxCount++
# 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"


Output:
Total Number of Mailboxes in database: 54
Total Size of Mailboxes: 270 MB
Total Items in Mailboxes: 55
-------------------
Average Mailbox Size: 5 MB
Average Items per Mailbox: 1.01851851851852

Comments