Creating a Mailbox Search Folder based on a Message Category using the Microsoft Graph and Powershell
Searching on the Categories property of an Email can pose a challenge because this property is a Multi-valued String property (which aren't that common in email) eg in a Message the property may look like the following
So this needs to be queried in a different way then a normal String or single valued property in an Email would, where you could use a number of filter options (eg equal, contains,startswith). In EWS it was only possible to query this property using AQS because of the way SearchFilters translated to the underlying ROP based restrictions used by the Exchange Mailbox Store. In the Microsoft Graph the Linq format in Filters does translate more favourably so can be used eg the following simple query can find Messages in a folder based on a specific category
https://graph.microsoft.com/v1.0/me/messages?filter=Categories/any(a:a+eq+'Green+Category')
you can create a SearchFolder based on this query which would search all folder in a Mailbox which would produce a SearchFolder Creation request like
{
"@odata.type": "microsoft.graph.mailSearchFolder",
"displayName": "Green Email",
"includeNestedFolders": true,
"sourceFolderIds": ["MsgFolderRoot"],
"filterQuery": "Categories/any(a:a+eq+'Green+Category')"
}
Based on a previous post on creating Search Folders I have this script https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/SearchFolder.ps1 which you can use to Create a Category Search folder as well as other SearchFolder CRUD operations eg
Invoke-CreateCategorySearchFolder -MailboxName user@domain.onmicrosoft.com -SearchFolderName CategoryTest -CategoryName "Category 1"