Searching O365 mailbox for all messages which don't contain [ in subject line

Darren Rose 281 Reputation points
2023-01-26T15:32:57.44+00:00

Trying to use PowerShell to search O365 mailbox to get all messages where subject line doesn't contain specific string, specifically a square bracket [

The command below works fine in principal to find all messages where subject contains a specific word, but can't get it to work to find all messages where subject DOES NOT contain a specific word (or in this case character [)

Search-Mailbox -Identity "fred@email.com" -SearchQuery 'Subject:"*" -[' -EstimateResultOnly

The eventual aim is to scan a mailbox to remove all content other than messages which contain square brackets in the subject line, so will use -DeleteContent switch or similar, for now just using -EstimateResultOnly or -LogOnly -LogLevel Full and -TargetFolder -TargetMailbox to see a list of what it finds

What am I missing - all comments appreciated.

Thanks

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,400 questions
Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,060 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,869 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Jame Xu-MSFT 4,166 Reputation points
    2023-01-27T08:54:30.5+00:00

    Hi @Darren Rose ,

    Some special characters aren't included in the search index and therefore aren't searchable.

    Refer to: Keyword queries and search conditions for eDiscovery

    User's image

    I tested in my environment and also could not match the special characters.

    User's image


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. Amit Singh 4,766 Reputation points
    2023-01-27T06:36:31.2266667+00:00

    Check this similar thread for help - https://stackoverflow.com/questions/66126319/search-string-substitute-variable-in-a-powershell-command


    Please Note: Since the web sites are not hosted by Microsoft, the links may change without notice. Microsoft does not guarantee the accuracy of this information.

    0 comments No comments

  3. Darren Rose 281 Reputation points
    2023-01-27T09:48:00.3666667+00:00

    Thanks for your reply - and for testing for me.

    That is really annoying then. Any thought on another way I can achieve this? is there a way in outlook or on outlook.com (owa) instead that I can search for all emails which DON'T contain square brackets [ or ] in the subject line?

    0 comments No comments

  4. Jame Xu-MSFT 4,166 Reputation points
    2023-01-31T06:58:13.28+00:00

    Hi @Darren Rose ,

    Sorry, "[" or "]" is also not available as searchable items in outlook, so there is no way to filter the emails you need, if your "[]" contains content, it is possible to search with the content.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.