Content Search Syntax

Glenn Maxwell 11,496 Reputation points
2020-09-04T03:19:20.57+00:00

Hi All

I want to delete spam emails from users mailbox.
Please validate the below syntax if its correct, i have 20 users who have received the spam email and i need to delete it, experts guide me.

syntax01--For All user
$Search=New-ComplianceSearch -Name "Remove Phishing Message" -ExchangeLocation All -ContentMatchQuery '(Received:09/01/2020 00:00..09/01/2020 23:59) AND (Subject:"Action required") AND (from:"someuser@ext.com")'
Start-ComplianceSearch -Identity $Search.Identity
New-ComplianceSearchAction -SearchName "Remove Phishing Message" -Purge -PurgeType SoftDelete -force

Syntax02--For Single user
$Search=New-ComplianceSearch -Name "RemoveMessage_John" -ExchangeLocation John@Company portal .com -ContentMatchQuery '(Received:09/01/2020 00:00..09/01/2020 23:59) AND (Subject:"Action required") AND (from:"someuser@ext.com")'
Start-ComplianceSearch "RemoveMessage_John"
New-ComplianceSearchAction -SearchName "RemoveMessage_John" -Purge -PurgeType SoftDelete -force

Syntax03-If i have 20 users in a csv file how do i delte the emails

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,576 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,667 questions
{count} votes

Accepted answer
  1. Eric Yin-MSFT 4,386 Reputation points
    2020-09-04T09:20:49.997+00:00

    syntax01: It's OK.

    syntax02: It seems Start-ComplianceSearch "RemoveMessage_John" will not be reported as error but in my test it's not starting the search, use Start-ComplianceSearch -Identity "name" instead.

    syntax03: An easy method is to manually add them to a group(GroupA) in ECP and run syntax1 with "-Exchangelocation GroupA", which should work for 20 users.
    Or you write a script to add group members, for example: Import-CSV FileName.csv | ForEach {Add-DistributionGroupMember -Identity "GroupName" -Member $_.Name}


    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.