Complex properties are one of the more challenging elements when it comes to developing with Exchange and bitwise properties are one of the more challenging property types you may need to deal with. The most common bitwise property in Exchange you may access/use is the PR_MessageFlags property https://msdn.microsoft.com/en-us/library/ee160304(v=exchg.80).aspx . If you look at this property on a Message that you received you might see something like
What the ExcludesBitmask SearchFilter/Restriction in EWS allows you to do is create a search where you can specifically exclude messages because they have one of these bitmask values set. Eg you might want to exclude Draft messages from your search or maybe you want to exclude any messages that where SentBy you in the Inbox. You can also 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 would then only get the message where the MSGFlag_HasAttached bit-wise is set.
Using this the EWS Managed API is pretty simple you first define the property you want to search on and then create a SearchFilter using this property and the Bitwise Value as the variable eg
This creates a SearchFilter that excludes draft messages, If you want to Negate that you can use
Which would then create a filter that just retrieved draft messages.
In PowerShell you can write a function like the following
The above function comes from the following script on Github https://github.com/gscales/Powershell-Scripts/blob/master/ExcludeQuery.ps1 demonstrates how to either get Items or a Summary count of those Items based on a bitwise flag exclusion or a negation of that exclusion. Again some examples may be in order
Example 1 Search for messages in the Inbox not sent from you using the mfFromMe bitwise flag
Query-MessageFlag -MailboxName email@example.com -FolderPath '\Inbox' -Flag 32 -SummaryOnly
Example 2 Search for messages in the Inbox sent from you using the mfFromMe bitwise flag (this is using a Negate filter)
Query-MessageFlag -MailboxName firstname.lastname@example.org -FolderPath '\Inbox' -Flag 32 -SummaryOnly -Negate
Example 3 Search for messages with the Attach Flag set in the Inbox mfHasAttach
Query-MessageFlag -MailboxName email@example.com -FolderPath '\Inbox' -Flag 16 -SummaryOnly -Negate
Example 4 Search for message with Read Recipient flag mfNotifyRead and Negate that
Query-MessageFlag -MailboxName firstname.lastname@example.org -FolderPath '\Inbox' -Flag 256 -SummaryOnly -Negate