A reader asks whether it is possible to browse through mailbox databases to view the details and statistics of the mailboxes they host on Exchange Server 2007 and 2010. You might recall this was simple to achieve using the Exchange Server 2003 System Manager tools.
The nearest equivalent feature in the Exchange Management Console is using filters in the Recipient Configuration/Mailboxes section of the console.
However this feature does not expose mailbox statistics such as item count and total size. For those types of details we can use the Exchange Management Shell instead.
For example, we can view the mailbox databases in the organization.
[PS] C:\>Get-MailboxDatabase Name Server Recovery ReplicationType ---- ------ -------- --------------- Mailbox Database 1 EXCH2010-TEST False None Mailbox Database 2 EXCH2010-TEST False None Mailbox Database 3 EXCH2010-TEST False None Mailbox Database 4 EXCH2010-TEST False None
Or to look at the mailboxes within a given database we can pipe one shell command into another.
[PS] C:\>Get-MailboxDatabase "Mailbox Database 1" | Get-Mailbox -ResultSize 15 Name Alias ServerName ProhibitSendQuota ---- ----- ---------- ----------------- Administrator Administrator exch2010-test unlimited Aisha.Bhari Aisha.Bhari exch2010-test unlimited Alan.Reid Alan.Reid exch2010-test unlimited Alannah.Shaw Alannah.Shaw exch2010-test unlimited Aldith.Walker Aldith.Walker exch2010-test unlimited Aleisha.Harrison Aleisha.Harrison exch2010-test unlimited Alex.Heyne Alex.Heyne exch2010-test unlimited Alice.Mullins Alice.Mullins exch2010-test unlimited Alison.Pugh Alison.Pugh exch2010-test unlimited Alison.Lindsay Alison.Lindsay exch2010-test unlimited Almaz.Duggan Almaz.Duggan exch2010-test unlimited Amanda.Watters Amanda.Watters exch2010-test unlimited WARNING: There are more results available than are currently displayed. To view them, increase the value for the ResultSize parameter.
We can also look at statistics such as item count and total mailbox size of all mailboxes in a given database.
[PS] C:\>Get-MailboxDatabase "Mailbox Database 1" | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount DisplayName TotalItemSize ItemCount ----------- ------------- --------- Administrator 1.402 GB (1,505,666,188 bytes) 72179 EXCH2010-TEST 4FE1F90C-LGU000009 84.46 MB (88,567,215 bytes) 2977 EXCH2010-TEST 4FE1F90C-LGU000012 77.23 MB (80,986,155 bytes) 2568 EXCH2010-TEST 4FE1F90C-LGU000011 71.99 MB (75,483,699 bytes) 2489 EXCH2010-TEST 4FE1F90C-LGU000010 70.77 MB (74,204,704 bytes) 2523 EXCH2010-TEST 4FE1F90C-LGU000019 54.73 MB (57,390,302 bytes) 1917 EXCH2010-TEST 4FE1F90C-LGU000001 51.48 MB (53,980,482 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000020 51.15 MB (53,634,243 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000015 50.92 MB (53,394,939 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000008 50.69 MB (53,153,806 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000016 50.68 MB (53,138,572 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000014 50.62 MB (53,079,853 bytes) 1741 EXCH2010-TEST 4FE1F90C-LGU000017 50.58 MB (53,035,273 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000005 50.53 MB (52,980,645 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000004 50.35 MB (52,795,218 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000000 50.31 MB (52,755,053 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000002 50.06 MB (52,490,485 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000023 50.05 MB (52,486,337 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000022 50.03 MB (52,464,722 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000003 49.87 MB (52,292,132 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000021 49.75 MB (52,170,805 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000007 49.6 MB (52,006,854 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000024 49.44 MB (51,841,314 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000018 49.31 MB (51,709,283 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000006 48.64 MB (50,999,424 bytes) 1725 EXCH2010-TEST 4FE1F90C-LGU000013 29.46 MB (30,886,139 bytes) 995
Alternatively, we can take a closer look at the mailbox statistics for one specific mailbox.
[PS] C:\>Get-MailboxStatistics -identity Administrator | fl RunspaceId : c3678368-5798-4340-8a0a-ab3f721b1a97 AssociatedItemCount : 131 DeletedItemCount : 0 DisconnectDate : DisplayName : Administrator ItemCount : 72179 LastLoggedOnUserAccount : DOMAIN\Administrator LastLogoffTime : LastLogonTime : 1/14/2010 2:19:58 PM LegacyDN : /O=TEST ORG/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=ADMINISTRATOR MailboxGuid : 9658e261-c681-40ac-ad6d-515791e28203 ObjectClass : Mailbox StorageLimitStatus : BelowLimit TotalDeletedItemSize : 0 B (0 bytes) TotalItemSize : 1.402 GB (1,505,666,188 bytes) Database : Mailbox Database 1 ServerName : EXCH2010-TEST DatabaseName : Mailbox Database 1 MoveHistory : IsQuarantined : False IsArchiveMailbox : False Identity : 9658e261-c681-40ac-ad6d-515791e28203 MapiIdentity : 9658e261-c681-40ac-ad6d-515791e28203 OriginatingServer : exch2010-test.domain.local IsValid : True
One of the common tasks that the Exchange Server 2003 System Manager was used for was exporting lists of mailbox users into CSV format for reporting in Excel. We can still achieve this in the Exchange Management Shell by exporting output to a CSV file.
[PS] C:\>Get-MailboxDatabase "Mailbox Database 1" | Get-MailboxStatistics | Sort totalitemsize -desc | Export-CSV C:\mailboxes.csv
The CSV output is formated correctly for easy import into Microsoft Excel.

As you can see although it may seem less intuitive than the previous method of browsing through a GUI the Exchange Management Shell actually makes it much simpler and easier to gather information about the mailboxes in your organization.





Tried your method to create a .csv for excel, but it does not work for me (Server-W2K8R2, Exch 2010 – Workstation-WinXP Pro SP3, Excel 2007). I even copied and pasted your line, changing only the database number and the drive to write the file to. Below is a partial of what I get. Strangely enough, it works when I display it. This would be a useful tool for one of my reports, if I can get it to work.
#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
ClassId2e4f51ef21dd47e99d3c952918aff9cd pageHeaderEntry pageFooterEntry autosizeInfo shapeInfo groupingEntry
033ecb2bc07a4d43b5ef94ed5a35d280 Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo
9e210fe47d09416682b841769c78b8a3
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c <(followed by about 40 lines of that)
Hi Scott, I can’t seem to replicate your error. Perhaps type out the command manually in case something is going awry in copy/paste?
No luck. Tried it letter-by-letter and space-by-space, and I still get the same results when I open the csv file. Everything works, but the “export” part of it. I will just use the display listing and go from there. That is still a big help.
Thanks for your time and assistance.
Hi Scott, remove the format-table part of the command, it should work then.
Get-MailboxDatabase “Mailbox Database 01″ | Get-MailboxStatistics | Sort totalitemsize -desc | Export-Csv C:\mailboxes.csv
“As you can see although it may seem less intuitive than the previous method of browsing through a GUI the Exchange Management Shell actually makes it much simpler and easier to gather information about the mailboxes in your organization”
You’ve got to be kidding? We’re now back in the 1980′s days of DOS, CPM and UNIX shell scripting. MS is not helping the everyday SMB sys admin, we’ve really got other things to do than figuring out cryptic scripts.
Nice work on the actual tutorial, well written and informative, keep it up.
“We’re now back in the 1980′s days of DOS, CPM and UNIX shell scripting. MS is not helping the everyday SMB sys admin”
You mean they’re not doing anything for the system admin who hasn’t learned anything since the ’80s.. The truth is, if you’re running a mail server for 50 people, you’re right – you might not get as much bang for the buck in learning Powershell, and a GUI is more your style, but then again, those small companies are probably migrating to GMAIL or Office365 and hiring a college student to manage it with the web GUI… If you’ve got a large enterprise of 25000 mailboxes, and you are tired of having to point and click at everything all day, and want to automate the mundane tasks, you’ll be MUCH BETTER OFF if you spend a day or so learning EXACTLY those commands described in this post, and learn to leverage them. There are SO MANY things you can do, from automating mailbox moves, doing reports, etc. that you could NEVER do in the old GUI. Besides – Microsoft has given a HUGE opening for someone to come behind (see Quest tools) to write a GUI front end management tool that would far exceed what Microsoft would have written in the first place.
I agree with Dan. What? Can’t the Exchange GUI run the Powershell commands here to create an easily accessible data output?
I have to now store all my scripts in text files and recall them when I need them then I have to modify the scripts and see what result I get.
I do love the 80s, but……………………
Hi Julian, I’ve been running a lot of these scripts lately as I work on migration planning. Personally it doesn’t bother me, I like being able to kick off the script and find a nicely formatted CSV file at the end. I get it that not everyone sees it that way.
The capability is probably there (though the exact steps are beyond me right now) to automate the process such that it collects this data on a scheduled basis and makes it available in a graphical report that you can look at when needed. I’m sure if you dug around some of the PowerShell dedicates blogs and websites you’d see some useful tips along those lines.
Yep.. I’ve got 26000 users spread across 5 servers and 104 databases, and I get daily reports on user counts on each server, which servers are filling up, what mailboxes are new each day, how many users have excessive mail counts in the “critical” folders, when each database was last backed up, etc.. all through powershell, delivered to me in email daily. Powershell is AWESOME. You can even build GUIs in PS if you do need something interactive with pull-down menus and pushbuttons.
Very Great Script, it Worked Like Charm
This works great! Worked the first time! I have different deparments on one database. After the export, I can sort by name, but I cannot get it to include the LDAP field “department”. This would help me GREATLY if I could export and sort by department to send out to the groups to clean up their mailboxes.
THANKS!
Sounds like you’ll need to knock up a script to combine the two pieces of data into one report
Very very understandable… Nice and good keep it up
all worked first time! Nice article.
How can we reduce the result set of get-mailboxstatistics command as you did with get-mailbox command useing resultsize. i just want to get only top 30 users e.g. and i have noticed that resultsize does not work with get-mailboxstatistics command.
Hi Faisal, I wrote an answer to your question here:
http://exchangeserverpro.com/powershell-tip-get-list-top-exchange-server-mailboxes-size
Hope that helps.
Hi Paul, Do you have a PS script to send this info as email?
Thanks
Vignesh
There’s a short series of articles here that walks you through sending emails from scripts:
http://exchangeserverpro.com/powershell-how-to-send-email
Paul, I noticed in your one PS command that the output showed GB, MB and bytes in () witout using any expressions. The best I am able to do is @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”} which would show MB rounded off (no decimal). How did you achieve this?
I did it using the command shown in the example. That is the standard output.
I get this error, can’t go any further
PS C:\> Get-MailboxDatabase
The term ‘Get-MailboxDatabase’ is not recognized as the name of a cmdlet, function, script file, or operable program. C
heck the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:20
+ Get-MailboxDatabase <<<<
+ CategoryInfo : ObjectNotFound: (Get-MailboxDatabase:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run it from the Exchange Management Shell.
Hei Paul
I´ve got a few questions, which i would like to help me solving:
Here windows 2k3 exc 2k7 sp1
get-mailboxstatistics | ft displayname,lastlogontime,storagelimitstatus,servername,{$_.TotalItemSize.Value.ToMB()}
How can i add the PrimarySmtpAddress to be listed using the ps?
Besides when export to a txt file; i get the short view, i mean dislpay name: Mario Can…. but not full field for any (storagelimitsstatus servername lastlogontime..etc)
I would like to use “| Export-Csv c:\test.csv” using the command shown before does not work; but it does in the next command
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv c:\mailbox_alias1.csv
Thanks for any advice you can give and specially for your time.
Regards