question

GlennMaxwell-2309 avatar image
GlennMaxwell-2309 asked ·

unable to delete email

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@contoso.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@contoso.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@contoso.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@contoso.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.

office-exchange-server-administrationoffice-exchange-online-itprooffice-exchange-server-mailflow
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@GlennMaxwell-2309
Did the above answers help? Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics.

0 Votes 0 · ·
KyleXu-MSFT avatar image
KyleXu-MSFT answered ·

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.

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GlennMaxwell-2309 avatar image
GlennMaxwell-2309 answered ·

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

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

KyleXu-MSFT avatar image
KyleXu-MSFT answered ·

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.

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidWilhoit-2657 avatar image
DavidWilhoit-2657 answered ·

or it didn't return
any results.

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

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.