Question

I'm using PowerShell to return a report of Exchange mailbox statistics as a tab-delimited text file. I'm having trouble with the ItemsInFolder property of the Get-MailboxFolderStatistics cmdlet (from the Microsoft.Exchange.Management.PowerShell.e2010 snapin). If I run it against a mailbox like this:

Get-MailboxFolderStatistics myusername -FolderScope Inbox | Select ItemsInFolder

it yields the following:

ItemsInFolder
-------------
          556

but the count in the inbox folder as viewed through Outlook is 513. I found this TechNet article that has a note that says

A mailbox can have hidden items that are never visible to the user and are only used by applications. The Get-MailboxFolderStatistics cmdlet can return hidden items for the following values: FolderSize, FolderAndSubfolderSize, ItemsInFolder, and ItemsInFolderAndSubfolders.

but I fairly certain this folder doesn't have any hidden items. Also, if I add a folder beneath the Inbox and move some items into it then run the cmdlet again, it reports the counts for BOTH folders:

ItemsInFolder
-------------
          547
           11

it's my understanding that the ItemsInFolderAndSubfolders property was supposed to return counts for sub-folders, not the ItemsInFolder property. So here are my questions:

  1. how do I get the cmdlet to return values for only the root folder provided, and
  2. how do I get it to return only items that are visible to the user?

No correct solution

OTHER TIPS

Instead of your current command, run this command, and look for the appropriate property/value pair in the command's output.

Get-MailboxFolderStatistics myusername -FolderScope Inbox | Select-Object -Property *;

That will retrieve all of the properties on the object, and allow you to find the appropriate one.

I figured out the answer to the first part of my question (how to return values for only the root, i.e. "Inbox"): add | Where-Object {$_.name -eq "Inbox"} to the call, as in:

Get-MailboxFolderStatistics myusername -FolderScope Inbox | Select ItemsInFolder | Where-Object {$_.name -eq "Inbox"}

Roryap, for the inbox folder statistics you should run:

Get-MailboxFolderStatistics -Identity myusername -FolderScope Inbox | ?{$_.FolderPath -like '/Inbox'} | Select Name, ItemsInFolder

That will first get the values for the mailbox, then filter to only top 'Inbox' folder (sometimes you can have other Inbox folders in other location ie for ipfx app), finally get the name and itemsInFolder.

Unfortunately that is not resolving the case of numbers being different in outlook and coming from the PS :(

If the Get-MailboxFolderStatistics cmdlet fails to distinguish between hidden and normal items, you might want to try "looking" at the folder via a mail client. I lifted most of the code below from another website:

$Outlook = New-Object -com Outlook.Application
$Session = $Outlook.Session
$Session.Logon()
$Inbox = $Outlook.Session.GetDefaultFolder(6)

$ItemCount = @(%{$Inbox.Items}).Count
$UnreadCount = @(%{$Inbox.Items | ?{$_.Unread}}).Count

[PSCustomObject]@{"Items"=$ItemCount;"Unread"=$UnreadCount}

I guess there is a version of doing this using Exchange Web Services too, but the basic idea is that if you want to see the mailbox like the end user does, access it via a mail client rather than query the mailbox store.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top