Forum Discussion
EXCHANGE-Online: powershell to get the number of mails in inbox not in a specific category
Hi All,
I have a specific question. I want via powershell get the number of mails in the inbox of a online shared mailbox that do not have a specific category....
Seems special request? Let me explain why i'm looking for it.
We have monitoring software that can execute powershells and get results of it.
I now want to monitor our dynamics 365 support mailbox to see if all mails are tranferred towards Dynamics365 correctly.
For this reason Dynamics 365 can read a specific mailbox inbox, to see if new mails have come in. When Dynamics 365 sees this, the mail gets "tracked" to Dynamics 365 and gets a category applied to it "Traced to Dynamics 365". In normal scenario, this works well, and mails get tracked etc....
Sometimes there are problems tracking. Sometime some mails are not tracked, sometimes the connector between Dynamics 365 and Exchange fails etc...
As we rely heavy on this mail traffic in our support department, this causes a problem if not cached.
So with this powershell i want to return a number, be it the number of mails without that category in the inbox. If this number gets too high.....then we have a problem and our monitor software can react and send alarms...
Any ideas would be appreciated..
Rgds
Benny Giebens
- Clifra_JonesCopper Contributor
Begie1605 The Command is Get-MailboxFolderStatistics
$items = (Get-MailBoxFolderStatistics -id user@email.com | Where-Object {$_.Name -eq "Inbox"}).ItemsInFolder
PowerShell can only give you the total number of items, it doesnt offer any way to filter by Category. You can easily do this in Outlook though, or if you need to do it programmatically, use EWS or the Graph API. Here's a sample article for the former: https://gsexdev.blogspot.com/2014/10/searching-based-on-categories-in-ews.html