Exchange_2010_logo_www.oostdam.infoExchange Server 2010 is a really beautifull product from Microsoft. Ofcourse these kind of products have difficulities of there own, but generally, there functionality is great. With the integration of the Exchange Powershell command line tools, the products took a great step forward, allowing (exchange)administrators lots of (scripting) possibilities and remote control of servers. This serie of articles has been made to share knowledge and provide some basic default scripting, which can be used on a (daily) basis through Exchange Powershell.  It can be an extra value for every organisation as "knowing" and "numbers" can be used in several ways, to discover (data)trends, excessions and as a basis for decisions and policies. These scripts are often used by myself on a regular basis, and I hope you like them! Have fun using powershell for Exchange !

The Get-MailboxStatistics cmdlet:
This Exchange Management (power)Shell (EMS) cmdlet is one of my favorite EMS commands to extract organizational data for my customers,and a baseline for reports, attention mails and conclusions towards the organization I manage the exchange 2010 servers for. Sure, you can find example commands almost everywhere, but they where not good enough for me. That why this article has been made to supply all the administrators in the world with a nice EMS line you can use, and the way I got to it explained on the side. Just google around and you will find lots of pages giving you examples. I'll gues this will become one of these pages in the future. You can even combine the Get-Mailbox and Get-MailboxStatistics if you want,.. But, as a Microsoft fan, I first must share this Technet article with you. So,.. now that done, lets start getting some output! 

We want to extract user specific data from our mailboxdatabase: 
This is simple, specify YourServerName after the cmdlet, as for reporting reasons you want to have the data of all users, therefore w'll totally skip the -Identity parameter in the article. If you do want it, just insert it in the lines, but I can see no reason to do this right now. The "DisplayName" gives you the name of the particular mailbox user. The EMS line will look like:

Get-MailboxStatistics -Server YOURSERVERNAME | ft DisplayName, TotalItemSize,ItemCount

Is that all there is: ? 
This is simple, but not good enough. You can find this cmdlet on hunderds of sites. They are just publishing it for the publishing reason and to have a relatively new article on there site. This list is a mess and only on screen, I cannot show a screen to the management, so lets export the whole list the common way. I'll guess you can find the export-csv version yourself, but now we are doing a simple text(.txt) file.

Get-MailboxStatistics -Server YOURSERVERNAME | ft DisplayName, TotalItemSize,ItemCount > D:\Reports\mailstatisticsCOMPANYNAME.txt

Aha, that a better report allready, is there more? 
Yes there is! This report is a total mess, lets first start sorting it to the way we want, namely, the largest mailbox on top! Everyone always looks at the largest mailboxes, smaller is better, while actually those are the people who often manage their messages the best way, but thats an understatement..  So, let sort the output on the largest mailbox above with the "Sort-Object" command.

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,TotalItemSize,ItemCount > D:\Reports\mailstatisticsCOMPANYNAME.txt

Aha, much nicer allready, is there more? 
Yes there is! Now we must must lose these ridiculous exact bytes numbers after the GB or MB size. This is not a nice, neath column, to width also, and I'm used to calculate in KB's anyway. So lets do that, but if you want it in GB's  or MB's,...  google a bit and you'll find that way in a couple of minutes. (Something like {$_.TotalItemSize.value.toMB()}. We add a variable with the calculation, nested within the EMS command line. We are doing this with the ".Value.ToKB" setting and the Label is there just for the header. Sorting is unchanged, only the value is converted. By the way, if your not able to follow this explanation until now,.. quit working with the EMS immediately and apply for a job at some servicedesk or something like that. So the EMS line is looking now something like: 

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount > D:\Reports\mailstatisticsCOMPANYNAME.txt

Much better indeed, can I see the number of Deleted Items as well? 
Yes you can!  I mainly use this column to see if users clean up their mailboxes on a regular basis. Now, deleted items still remain within the actual mailbox size until the retention time is over, but you should now that by now! If your working with quota limitations on mailboxdatabases you will understand soon enough. We skip all the converting crap like above and directly add the calculated KB size and items to our EMS line which is now looking like:

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,@{label="TotalDeletedItemSize(KB)";expression={$_.TotalDeletedItemSize.Value.ToKB()}},DeletedItemCount > D:\Reports\mailstatisticsCOMPANYNAME.txt

Very nice now, but I cannot read the full names anymore? 
Oeps, forgot to tell you that,...  By default the EMS uses the default width, also for reporting, other then the Export-CSV. So lets fix that! We can use the "-AutoSize" parameter for adjusting the column width and the "-Out-String" parameter is taking care of the available width. Our EMS command line now changes to:

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,@{label="TotalDeletedItemSize(KB)";expression={$_.TotalDeletedItemSize.Value.ToKB()}},DeletedItemCount -AutoSize  | Format-Table -Property * -AutoSize | Out-String -Width 4096 > D:\Reports\mailstatisticsCOMPANYNAME.txt

So now, w're getting somewhere, but some users seem to never delete any items? 
Yes thats true, there are still users out there that don't use their mailbox within an organization. They are to busy with their core tasks or do not have the skills to use (web)mail. They rather talk to their colleagues than mail them. Sometimes thats even better and preferred. Colleagues often talk to little to eachother in my opinion. To solve this lack of information we add the "-LastLogonTime" parameter to the end of our EMS line:

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,@{label="TotalDeletedItemSize(KB)";expression={$_.TotalDeletedItemSize.Value.ToKB()}},DeletedItemCount,lastLogonTime -AutoSize  | Format-Table -Property * -AutoSize | Out-String -Width 4096 > D:\Reports\mailstatisticsCOMPANYNAME.txt

Are we done, or are there more usefull things? 
No, w're not done yet, there are at least 2 more parameters I would like to share with you. First the "-DatabaseName" a mailbox resides in. I'm an administrator who likes to work with multiple database, the more the better. The reason for that is mainly thats its easier to manage in various ways. Quota limitations, special retentions, journaling and (hub)rules to name a few examples. Besides that, it is much easier to restore (or do maintanance) on a database for a group of users, rather than setting the whole organization directly offline. That is, in case you are not able to use Database Availability Groups (DAG) in your organization ofcourse. The second handy parameter in my opinion is the "-StorageLimitStatus". I use this to see if users received a quota warning message and it is also helpfull on troubleshooting or helping users when they reached the ProhibitSend status. So,...  lets put these parameters in our EMS line as well.

Get-MailboxStatistics -Server YOURSERVERNAME | Sort-Object TotalItemSize -Descending | ft DisplayName,DatabaseName,StorageLimitStatus,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,@{label="TotalDeletedItemSize(KB)";expression={$_.TotalDeletedItemSize.Value.ToKB()}},DeletedItemCount,LastlogonTime -AutoSize  | Format-Table -Property * -AutoSize | Out-String -Width 4096 > D:\Reports\mailstatisticsCOMPANYNAME.txt

Now, this it for now. I'll provide you with some additional tips below and use your own imagination to implement this further in your EMS line. You can schedule this EMS line on one of your exchangeservers and have the output sent to your mailbox on a regular basis. Please make sure to load the exchange 2010 snapin first befor executing this EMS line, otherwise it will never work. The line needed is: Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

I hope this has been informative for you, and I like to thank you for reading this article. I case you might have better suggestions? Please contact me on Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken. (delete the remove letters) and I'll add it to this article. Have fun, using Exchange Management Shell!

Tip1: Create a cutom label name to keep smaller default columns.
Tip2: Make use of the "-Filter" parameter in combination with the Get-Mailbox cmdlet. 
         I'll try to provide you with some more examples in a couple of weeks.
Tip3: Make use of the "LastLoggedOnUserAccount" parameter to see who is using shared mailboxes.
Tip4: Make use of the "LastLogoffTime" parameter to see the last logoff time.
Tip5: Make use of the "-ResultSize Unlimited" parameter if you don't see everything in the output.
         (in combination with the "Get-Mailbox" cmdlet to get all mailboxes over multiple exchange servers)
Tip6: Make use of the "-IgnoreDefaultScope" parameter.
         (in combination with the "Get-Mailbox" cmdlet to get all mailboxes over multiple exchange servers)
Tip7: Make use of the "MailboxGuid" parameter to get that crazy long number.
Tip8: Make use of the "| Export-CSV" option to export the data in csv format.

Printscreen: not available

Ben OostdamBen Oostdam has been working with Windows systems since 1993. Worked for several companies as a system administrator, and is currently a Senior Support Engineer for a large company in the Netherlands.

Disclaimer: The information contained in this website/article is for general information purposes only. The information is provided as is, by Ben Oostdam and others, and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk. In no event will we be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website. Through this website you are sometimes able to link to other websites which are not under my control. I have no control over the nature, content and availability of those sites. The inclusion of any links does not necessarily imply a recommendation or endorse the views expressed within them. Every effort is made to keep the website up and running smoothly. However, I take no responsibility for, and will not be liable for, the website being temporarily unavailable due to technical issues beyond our control. All entries in these articles, are my individual opinion, or from co-writers, and they don't necessary reflect the opinion of my employer.


Friday the 7th, May 2021. All rights reserved.. // Oostdam WebDesign