Discussion on:

5
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
If it has not been covered previously, it is also worth dumping a list of user folders based on a chosen item count limit. Exchange is not really affected by the size of a mailbox but rather the number of items in a single folder (items in a table in the exchange database).

For dumping a list of all user folders with more than X (eg. 5000) items sorted by username, folder item count and redirected to a text file:

[command/script example removed. aperently including it makes TR's CMS display only the first and last line of my comment.]

(I need to take five minutes and write this into proper shell script one day soon)
i like that - but in my environment we have two mailbox clusters, and LOTS of databases - so i tweaked the script slightly - this version simply accesses all mailbox databases, and outputs the same information for each database, and then a total for all databases


# Retrieve the list of mailboxes from all mailbox databases on all servers

$listofmailboxdatabases = get-mailboxdatabase
$totalmailboxcount = 0
$totalmailboxtotalitemcount = 0
$totalmailboxtotalsize = 0

# start a loop that will check each mailbox database
foreach ($individualdatabase in $listofmailboxdatabases)
{

$listOfMailboxes = Get-MailboxDatabase $individualdatabase | 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
Write-Host "Stats for mailbox database $individualdatabase"
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"
$totalmailboxcount = $totalmailboxcount + $mailboxCount
$totalmailboxtotalsize = $totalmailboxtotalsize + $mailboxTotalSize
$totalmailboxtotalitemcount = $totalmailboxtotalitemcount + $mailboxTotalItemCount
}

# Calculate the average mailbox size
$totalmailboxAverageSize = $totalmailboxtotalsize / $totalmailboxcount

# Calculate the average number of items per mailbox
$totalmailboxAverageItemCount = $totalmailboxtotalitemcount / $totalmailboxcount

Write-Host "-------------------"
Write-Host "-------------------"
Write-Host "Total Number of Mailboxes: $totalmailboxcount"
Write-Host "Total Size of Mailboxes: $totalmailboxtotalsize MB"
Write-Host "Total Items in Mailboxes: $totalmailboxtotalitemcount"
Write-Host "-------------------"
Write-Host "Average Mailbox Size: $totalmailboxAverageSize MB"
Write-Host "Average Items per Mailbox: $totalmailboxAverageItemCount"
0 Votes
+ -
script error
jadham 23rd Nov 2011
I had a problem running it on our Exchange 2010. Please see below:

The term 'Get-MailboxDatabase' is not recognized as the name of a cmdlet, function, script file, or operable program.
heck the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\mailboxstats.ps1:3 char:39
+ $listOfMailboxes = Get-MailboxDatabase "Mailbox Database 1081629644" | Get-Mailbox
+ CategoryInfo : ObjectNotFound: (Get-MailboxDatabase:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

The term 'Get-MailboxStatistics' is not recognized as the name of a cmdlet, function, script file, or operable progra
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\mailboxstats.ps1:24 char:56
+ $individualMailboxStats = Get-MailboxStatistics -Identity $individualMailbox
+ CategoryInfo : ObjectNotFound: (Get-MailboxStatistics:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

You cannot call a method on a null-valued expression.
At C:\mailboxstats.ps1:27 char:82
+ $individualMailboxSize = $individualMailboxStats.TotalItemSize.value.toMB ()
+ CategoryInfo : InvalidOperation: (toMB:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I added this line at the beginning to automate the process for those of us with mulitple databases. It simply prompts you for the DB name.

$maildb = read-host "Enter the mailbox database name"

Then I slightly modified the second line:

$listOfMailboxes = Get-MailboxDatabase $maildb | Get-Mailbox

Awesome script! I'm working on setting up database size limits and this came in handy.
Will this work with MS BPOS or Office 365 or is it for in house Exchanges?
Thanks
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.