Exchange 2010 PowerShell script count items in mailbox folder

This post is also available in: Polish

As is known, together with new versions of Microsoft Exchange are changing also limits the number of elements in a single folder mailbox.

For each version of Exchange, Microsoft recommends not to exceed the following values of the number of items in the folder:

Exchange 200/2003        5 000
Exchange 2007               20 000
Exchange 2010             100 000

Number of items contained in folders determines the performance of the server and connections to the mailbox, can also cause problems with the use of mail clients.

If you want to monitor the number of elements in the mailbox or in folders for this purpose we use PowerShell scripts written, started at a time in TaskScheduler.

This script checks all the mailboxes on the server, and if the amount of all items in the mailbox exceeds the value specified in the $Items_max then this will be reported in box.

$data = $((get-date).ToString('dd.MM.yyyy'))
Function New-Array {,$args}
$Report = New-Array
$Items_max = 500
$mbxs = get-mailbox -resultsize unlimited
foreach ($mbx in $mbxs){
 $mbxstat = get-mailboxstatistics $mbx.SAMAccountName
 if ($mbxstat.ItemCount -gt $Items_max){
   $report_tmp = New-Object System.Object
   $report_tmp | Add-Member -type NoteProperty -name DisplayName -value $mbx.DisplayName
   $report_tmp | Add-Member -type NoteProperty -name ItemCount -value $mbxstat.ItemCount
 $Report += $report_tmp
$Report | ft -auto | Out-String -Width 4096 > d:\scripts\report_itemscount_$data.txt
Send-MailMessage -To -From -Subject "Mailbox items count $data" -SmtpServer youremailserver -Attachments d:\scripts\report_itemscount_$data.txt


On TechNet pages is also available HighItemFolders.ps1, powerful script, that checks the number of elements in each folder and if more than the recommended limit, the report is saved to a file .csv or is displayed on the screen.

The script has the following parameters, which are all optional:

  •  CriticalFoldersOnly: Specifies whether to check only Critical Folders, which are Calendar, Contacts, Inbox, and Sent Items, or to check all folders. Should be specified as either $true or $false. If omitted, the default value is $true.
  • Database: Specifies the target database to retrieve mailboxes from. This switch overrides the -Server switch if both are used.
  • DomainController: Specifies the Domain Controller to use for all mailbox and folder tests. If omitted, the default value is $null.
  • FormatList: Writes output to the screen in list format instead of table format. Should be input as either $true or $false. If omitted, the default value is $false.
  • ItemCount: Ignores the Microsoft recommended item limits, and finds folders with the specified item count.
  • OutputFile: Specifies the file to output the results to. This should be a .CSV file.
  • ResultSize: Specifies the maximum number of mailboxes to check. If omitted, the default value is unlimited.
  • Server: Specifies the target Exchange server to retrieve mailboxes from.


Obtains all users in the organization, and checks only critical folders over the Microsoft recommended item counts:

c:\> .\HighItemFolders.ps1

Obtains all users on a specified database, checks all folders, and outputs to a CSV file:

C:\>.\HighItemFolders.ps1 -Database "MBXServer\MailboxDatabase" -CriticalFoldersOnly $false -OutputFile d:\scripts\output.csv


Print Friendly
Tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>