none
New-ComplianceSearch RRS feed

  • Question

  • Hi All

    i have a requirement to delete spam email from few users as search mailbox is going to depreciate how do i use new compliance search and delete emails. i have 10 users in csv file, 
    below is my requirement experts help me with new syntax

    Name
    user1@contoso.com
    user2@contoso.com

    is the below syntax correct and in this syntax how can i import the csv file, will -force work and the subject i want should be exact Spam TEST and not Re:Spam TEST or FW:Spam TEST

    $Search=New-ComplianceSearch -Name "test" -ExchangeLocation "searchlocation" -ContentMatchQuery '(Received:06/10/2020..06/15/2020) AND (Subject:"Spam TEST") AND (From:"ext@test.com")'
    Start-ComplianceSearch -Identity $Search.Identity
    New-ComplianceSearchAction -SearchName "remove message" -Purge -PurgeType SoftDelete -force

    Thursday, June 18, 2020 2:37 PM

Answers

  • Hi Glenn Maxwell

    From this article, we can know that compliance search can only find email which contains rather than equal the keywords:

    You can import the users as below:

    $Mailboxes = Import-Csv c:/temp/stmp.csv
    ForEach ($Mailbox in $Mailboxes){
        New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:06/10/2020..06/15/2020) AND (Subject:"Spam TEST") AND (From:"ext@test.com")'
        Start-ComplianceSearch -Identity $mailbox.name
        New-ComplianceSearchAction -SearchName $mailbox.name -Purge -PurgeType SoftDelete -force
    }

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Friday, June 19, 2020 2:26 AM
    Moderator
  • tthe emails are not deleted even after 2 hours, i have selected todays date range and one mailbox

    It seems that you changed the script I provided. By the way, it isn't possible exit "**@contoso.com" on Exchange online.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    • Marked as answer by Glenn Maxwell Monday, August 3, 2020 4:42 PM
    Monday, June 29, 2020 6:45 AM
    Moderator

All replies

  • Hi Glenn Maxwell

    From this article, we can know that compliance search can only find email which contains rather than equal the keywords:

    You can import the users as below:

    $Mailboxes = Import-Csv c:/temp/stmp.csv
    ForEach ($Mailbox in $Mailboxes){
        New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:06/10/2020..06/15/2020) AND (Subject:"Spam TEST") AND (From:"ext@test.com")'
        Start-ComplianceSearch -Identity $mailbox.name
        New-ComplianceSearchAction -SearchName $mailbox.name -Purge -PurgeType SoftDelete -force
    }

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Friday, June 19, 2020 2:26 AM
    Moderator
  • Hi Glenn Maxwell

    I am writing here to confirm with you how thing going now?

    If the above suggestion helps, please be free to mark it as an answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Tuesday, June 23, 2020 6:01 AM
    Moderator
  • tthe emails are not deleted even after 2 hours, i have selected todays date range and one mailbox
    Thursday, June 25, 2020 3:10 PM
  • tthe emails are not deleted even after 2 hours, i have selected todays date range and one mailbox

    It seems that you changed the script I provided. By the way, it isn't possible exit "**@contoso.com" on Exchange online.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    • Marked as answer by Glenn Maxwell Monday, August 3, 2020 4:42 PM
    Monday, June 29, 2020 6:45 AM
    Moderator
  • i am using the below script
    $Mailboxes = Import-Csv C:/list.csv
    ForEach ($Mailbox in $Mailboxes){
        New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:06/10/2020 00:00..06/15/2020 23:59) AND (Subject:"Spam TEST") AND (From:"ext@test.com")'
        Start-ComplianceSearch -Identity $mailbox.name
        New-ComplianceSearchAction -SearchName $mailbox.name -Purge -PurgeType SoftDelete -force
    }

    Tuesday, June 30, 2020 11:35 AM
  • i am using the below script
    $Mailboxes = Import-Csv C:/list.csv
    ForEach ($Mailbox in $Mailboxes){
        New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:06/10/2020 00:00..06/15/2020 23:59) AND (Subject:"Spam TEST") AND (From:"ext@test.com")'
        Start-ComplianceSearch -Identity $mailbox.name
        New-ComplianceSearchAction -SearchName $mailbox.name -Purge -PurgeType SoftDelete -force
    }

    Remove all existing compliance search from admin center and create it again. And, make sure search with the real mailbox.

    Regards, 

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Thursday, July 2, 2020 7:51 AM
    Moderator
  • Hi Glenn Maxwell,

    Any update about this thread now?

    If the above suggestion helps, please be free to mark it as an answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Friday, July 3, 2020 6:32 AM
    Moderator