EXCHANGE-Online: powershell to get the number of mails in inbox not in a specific category

%3CLINGO-SUB%20id%3D%22lingo-sub-1900451%22%20slang%3D%22en-US%22%3EEXCHANGE-Online%3A%20powershell%20to%20get%20the%20number%20of%20mails%20in%20inbox%20not%20in%20a%20specific%20category%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1900451%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3EI%20have%20a%20specific%20question.%20I%20want%20via%20powershell%20get%20the%20number%20of%20mails%20in%20the%20inbox%20of%20a%20online%20shared%20mailbox%20that%20do%20not%20have%20a%20specific%20category....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESeems%20special%20request%3F%20Let%20me%20explain%20why%20i'm%20looking%20for%20it.%3C%2FP%3E%3CP%3EWe%20have%20monitoring%20software%20that%20can%20execute%20powershells%20and%20get%20results%20of%20it.%3C%2FP%3E%3CP%3EI%20now%20want%20to%20monitor%20our%20dynamics%20365%20support%20mailbox%20to%20see%20if%20all%20mails%20are%20tranferred%20towards%20Dynamics365%20correctly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20this%20reason%20Dynamics%20365%20can%20read%20a%20specific%20mailbox%20inbox%2C%20to%20see%20if%20new%20mails%20have%20come%20in.%20When%20Dynamics%20365%20sees%20this%2C%20the%20mail%20gets%20%22tracked%22%20to%20Dynamics%20365%20and%20gets%20a%20category%20applied%20to%20it%20%22Traced%20to%20Dynamics%20365%22.%20In%20normal%20scenario%2C%20this%20works%20well%2C%20and%20mails%20get%20tracked%20etc....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESometimes%20there%20are%20problems%20tracking.%20Sometime%20some%20mails%20are%20not%20tracked%2C%20sometimes%20the%20connector%20between%20Dynamics%20365%20and%20Exchange%20fails%20etc...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20we%20rely%20heavy%20on%20this%20mail%20traffic%20in%20our%20support%20department%2C%20this%20causes%20a%20problem%20if%20not%20cached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20with%20this%20powershell%20i%20want%20to%20return%20a%20number%2C%20be%20it%20the%20number%20of%20mails%20without%20that%20category%20in%20the%20inbox.%20If%20this%20number%20gets%20too%20high.....then%20we%20have%20a%20problem%20and%20our%20monitor%20software%20can%20react%20and%20send%20alarms...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20would%20be%20appreciated..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERgds%3C%2FP%3E%3CP%3EBenny%20Giebens%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1900451%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDynamics%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Email%20flow%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1901235%22%20slang%3D%22en-US%22%3ERe%3A%20EXCHANGE-Online%3A%20powershell%20to%20get%20the%20number%20of%20mails%20in%20inbox%20not%20in%20a%20specific%20category%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1901235%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F873283%22%20target%3D%22_blank%22%3E%40Begie1605%3C%2FA%3E%26nbsp%3B%20The%20Command%20is%20Get-MailboxFolderStatistics%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24items%20%3D%20(Get-MailBoxFolderStatistics%20-id%20user%40email.com%20%7C%20Where-Object%20%7B%24_.Name%20-eq%20%22Inbox%22%7D).ItemsInFolder%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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

2 Replies

@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