Incorrect totals from exchange Get-MailboxFolderStatistics cmdlet

I am trying to use PowerShell to provide me with the total number of items that a user has in their Inbox. This will help in managing users who are not organising their email system properly. (in the past we have had users with 4000+ emails in their Inbox!
I run this in the Exchange 2010 Management Shell:

Get-Mailbox | Get-MailboxFolderStatistics | Where {$_.Name -match "Inbox"} | Select Identity, Name, ItemsInFolder | Sort-Object ItemsInFolder -descending | Export-csv c:\temp\MailboxItemCountInbox.csv

It looked like it provided what I needed until I looked at the totals. Mine for instance.
The spreadsheet from the above command shows that I have 190 items in my Inbox. I actually have 156!
I understand (from other forums) that this command will also take into account unopened emails.
I have unopened:
66 Deleted
21 drafts
4 Saved Folder
145 Junk Mail
No matter which way I look at these figures i cannot get them to add up to the 190 items reported.
I find this with all the other users.

Am I missing something in the command that will give me an accurate snapshot of the number of items in a users Inbox?

Thanks for your time in viewing this post
Neil RandallAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Muhammad MullaSystems AdministratorCommented:
Are you just looking for items in the inbox folder or in all folders in the mailbox.

Bear in mind that mailbox folders includes calendar and contacts folders.
Will SzymkowskiSenior Solution ArchitectCommented:
Are you using cached mode on your mailbox? Depending on the state of your OST it could be off slightly compared to your mailbox on the server. Also depending how much you are caching to this OST file as well.

Try Outlook in online mode and see if the count is the same. If it is and is only different when using cached mode this is excepted.

Neil RandallAuthor Commented:
For now I am only looking for the total number of mail items in each users mailbox. Once I can get this sorted, I would want to run the procedure against Sent Items and Deleted Items.

Will Szymkowski
I am using cached mode and have always known there is some lag between the client and the server. However if anything the count in my Outlook client should show more items, just going of the data file properties - folder size - of the Inbox Folder. The server shows less than the client!
It is not just 1 or 2 items out, it is 30 - 40 items out in the count 190+ in the report from Exchange but 150+ items in my Inbox.
I have run this a couple of times this afternoon with very little changing (in fact my mailbox has been very quiet over the last 24 hours, for once!).
It just looks like there is something else the command is including in the output rather than just the number of items in each Inbox.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Will SzymkowskiSenior Solution ArchitectCommented:
The most accurate information you are going to get it from the Exchange server directly. I would be referencing these results and not the cached OST file.

Using either
Get-MailboxStatistics -Identity <user>

Open in new window


Get-MailboxFolderStatistics -Identity <user>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil RandallAuthor Commented:
Thanks Will

I tried this on the server using the Exchange Shell, but this command will only give me 'Total' stats for all mail items in a user's mailbox. I am trying to get a snapshot count of how many mail items (opened & unopened) there are in every users Inbox only.

Will SzymkowskiSenior Solution ArchitectCommented:
I do not believe you can do this with native powershell cmdlets. I would try the suggestion at the following link.
Outlook UnRead Item Count

Neil RandallAuthor Commented:
Thanks Will

You pointed me in the right direction, but this finally got me closer to what I want.

It still does not give me an exact or 'live' total, but is usually within 20 - 30 items. As I am only interested in those users who have hundreds of emails in their Inbox, or are nesting folders in their Inboxes, this solution just about does the job.

Get-Mailbox | Get-MailboxFolderStatistics -FolderScope All | Sort-Object FolderSize -Descending | Where-Object {$_.FolderPath -like "/Inbox*"} | select-object Identity,FolderSize,ItemsInFolder |  Export-Csv c:\temp\MailBoxItemCount.csv
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.