unable to delete email

Glenn Maxwell 10,046 Reputation points
2020-08-03T16:50:28.413+00:00

Hi Experts i want to delete an email i am getting the below error.
i have a csv file in the below format.

Name
user1@Company portal .com

i am using the below syntax

$Mailboxes = Import-Csv C:/list.csv
ForEach ($Mailbox in $Mailboxes){
New-ComplianceSearch -Name $mailbox.name -ExchangeLocation $mailbox.name -ContentMatchQuery '(Received:08/01/2020 00:00..08/01/2020 23:59) AND (Subject:"testemail") AND (From:"externalusre@ext.com")'
Start-ComplianceSearch -Identity $mailbox.name
New-ComplianceSearchAction -SearchName $mailbox.name -Purge -PurgeType SoftDelete -force
}

i am getting below error, how i delete existing compliance search using shell

The compliance search object "user1@Company portal .com" already exists within your organization.
Confirm
Are you sure you want to perform this action?
This operation will make message items meeting the criteria of the compliance search "user1@Company portal .com"
completely inaccessible to users. There is no automatic method to undo the removal of these message items.
[Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is "Y"): A
Unable to execute the task. Reason: The search "user1@Company portal .com" is still running or it didn't return
any results. Please wait until the search finishes or edit the query and run the search again.

  1. If i need to delete meeting invite how do i need to delete it do i need to use Kind:meeting if so how can i add it.
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,153 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,327 questions
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,206 Reputation points
    2020-08-04T02:11:29.71+00:00

    About the error you that get, it is caused by duplicate task name. So, you need to stop and delete all exist Compliance Search before running that script.

    Get-ComplianceSearch | Remove-ComplianceSearch -Confirm:$false
    

    About the another question that you asked at the end, I noticed that you have ask it in another thread already, for better discussion and other people’s searches, you may need to continue follow in that thread.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Glenn Maxwell 10,046 Reputation points
    2020-08-04T05:01:17.867+00:00

    How can i know the name of the compliance search which is duplicate so that i can delete that compliance search
    if i use the below syntax i may be deleting all the compliance searches
    Get-ComplianceSearch | Remove-ComplianceSearch -Confirm:$false

    0 comments No comments

  2. KyleXu-MSFT 26,206 Reputation points
    2020-08-06T10:34:20.61+00:00

    That script use the mailbox name in your CSV file to create compliance search request.
    So, have a check about exiting compliance search request, whether there exist any request which named by the mailbox name in your CSV file. If there are, delete them before running that script.

    0 comments No comments

  3. David Wilhoit 1 Reputation point
    2020-08-14T15:43:09.12+00:00

    or it didn't return
    any results.

    Have you verified that message was in the user's mailbox?

    0 comments No comments