Utilizing the ExcludesBitmask SearchFilter Restriction in EWS Advanced properties are one of many tougher parts in relation to growing with Trade and bitwise properties are one of many tougher property varieties you might have to take care of. The commonest bitwise property in Trade you might entry/use is the PR_MessageFlags property https://msdn.microsoft.com/en-us/library/ee160304(v=exchg.80).aspx . In the event you take a look at this property on a Message that you simply acquired you may see one thing like
What the ExcludesBitmask SearchFilter/Restriction in EWS means that you can do is create a search the place you may particularly exclude messages as a result of they’ve one in all these bitmask values set. Eg you may wish to exclude Draft messages out of your search or possibly you wish to exclude any messages that the place SentBy you within the Inbox. It’s also possible to use this Search Filter with the Not filter which Negates the restriction so if I created a Searchfilter to excluded all messages with the MSGFlag_HasAttached then negated that with the Not filter I’d then solely get the message the place the MSGFlag_HasAttached bit-wise is ready.
Utilizing this the EWS Managed API is fairly easy you first outline the property you wish to search on after which create a SearchFilter utilizing this property and the Bitwise Worth because the variable eg
This creates a SearchFilter that excludes draft messages, If you wish to Negate that you need to use
Which might then create a filter that simply retrieved draft messages.
In PowerShell you may write a operate like the next
The above operate comes from the next script on Github https://github.com/gscales/Powershell-Scripts/blob/grasp/ExcludeQuery.ps1 demonstrates tips on how to both get Gadgets or a Abstract depend of these Gadgets primarily based on a bitwise flag exclusion or a negation of that exclusion. Once more some examples could also be so as
Instance 1 Seek for messages within the Inbox not despatched from you utilizing the mfFromMe bitwise flag
Question-MessageFlag -MailboxName firstname.lastname@example.org -FolderPath ‘Inbox’ -Flag 32 -SummaryOnly
Instance 2 Seek for messages within the Inbox despatched from you utilizing the mfFromMe bitwise flag (that is utilizing a Negate filter)
Question-MessageFlag -MailboxName email@example.com -FolderPath ‘Inbox’ -Flag 32 -SummaryOnly -Negate
Instance Three Seek for messages with the Connect Flag set within the Inbox mfHasAttach
Question-MessageFlag -MailboxName firstname.lastname@example.org -FolderPath ‘Inbox’ -Flag 16 -SummaryOnly -Negate
Instance Four Seek for message with Learn Recipient flag mfNotifyRead and Negate that
Question-MessageFlag -MailboxName email@example.com -FolderPath ‘Inbox’ -Flag 256 -SummaryOnly -Negate