Exchange Inbox Report

I am wanting to send a daily report to our managers that will let them know how many emails are in someones inbox. The script I have so far is below. The problem is Get-MailboxFolderStatistics also reports hidden items in that folder. So it is not a realistic number of emails in their inbox. Does anyone have an idea on how to list only the emails and not the hidden content?

Get-DistributionGroupMember -Identity "CS" | Get-Mailbox | Get-MailboxFolderStatistics -IncludeOldestAndNewestItems | Where {$_.Name -match “Inbox”} | Select Identity, Name, ItemsInFolder, OldestItemReceivedDate, NewestItemReceivedDate | Sort-Object ItemsInFolder -descending | Export-csv c:\MailboxItemCountInbox.csv

Depending on how many mailboxes you are looking at, if not to many, you could do new-mailboxsearch

edit: completely missread the post thought you wanted just the mailer

 

This should do the trick

 

[pre]

Get-DistributionGroupMember -Identity “CS” | Get-Mailbox | Get-MailboxFolderStatistics -IncludeOldestAndNewestItems | Where {$_.Name -match “Inbox”} | Select Identity, Name, ItemsInFolder, OldestItemReceivedDate, NewestItemReceivedDate | Sort-Object ItemsInFolder -descending | Export-csv c:\MailboxItemCountInbox.csv

$smtpServer = “smtp.domain.com
$From = “NoReply@domain.com
$Subject = “Mailbox Results”
$Body = “Attached are the results of mailbox query ran on the mailbox CS”
$attachment = “c:\MailboxItemCountInbox.csv”
$to = “someone@domain.com
$bcc = “Yourself@domain.com

#Mail
Send-Mailmessage -smtpServer $smtpServer -from $from -to $to -Bcc $bcc -subject $subject -priority High -Body $Body -attachment $attachment

[/pre]

My thought was have it list only the email between the OldestItemReceivedDate and NewestItemReceivedDate but I haven’t figured out how to make that work yet. I also looked into using the Mailboxsearch but couldn’t figure out how to make it search only the users’ inboxes and provide a count only.

This should do it for you.

Get-DistributionGroupMember -Identity "CS" | foreach { Get-MailboxFolderStatistics $_.alias | where { $_.name -eq "inbox" } | select Identity, ItemsInFolder, ItemsInFolderAndSubfolders}

 

This still lists hidden data in the inbox because you are using the Get-MailboxFolderStatistics without anyway of filtering the results.

I don’t understand what is hidden in the inbox or inbox and subfolders?
when you return results for just those foldernames it should be showing the correct count
Outlook on the other hand may be doing some kind of filtering not showing the messages. But that would be totally client side.