Get-ComplianceSearch is really not intended for mass delete scenarios, as you can remove only 10 items at a time. The good old Search-Mailbox cmdlet is still available and will do the trick.
Other than that, you need to understand that messages are not immediately deleted even with HardDelete switch, as there are functionalities such as Single item recovery, retention and holds at play. Refer to this article for information on all the "moving parts": https://learn.microsoft.com/en-us/microsoft-365/compliance/delete-items-in-the-recoverable-items-folder-of-mailboxes-on-hold?view=o365-worldwide
How do I delete emails in all inboxes using PowerShell?
Sergey Ryzhkin
21
Reputation points
Hello!
Can't delete files found by search.
Created a search, checked that it was created and completed, using the command - Get-ComplianceSearch
Result:
PS C:\WINDOWS\system32> Get-ComplianceSearch -Identity "search3"| FL name,items,size,jobprogress,status
Name : search3
Items : 19000
Size : 6242776347
JobProgress : 100
Status : Completed
Next, I ran the uninstall with the command:
New-ComplianceSearchAction -SearchName "search3" -Purge -PurgeType SoftDelete (I also tried HardDelete).
Result:
PS C:\WINDOWS\system32> Get-ComplianceSearchAction -Identity "search3_Purge"
Name SearchName Action RunBy JobEndTime Status
---- ---------- ------ ----- ---------- ------
search3_Purge search3 Purge Администратор О365 09.03.2022 5:11:23 Completed
After that, I ran the search again to check, but nothing was removed. The files are still there. I went into the user's mailboxes, the letters have not gone away.
PS C:\WINDOWS\system32> Get-ComplianceSearch -Identity "search3"| FL name,items,size,jobprogress,status
Name : search3
Items : 19000
Size : 6242776503
JobProgress : 100
Status : Completed
How do I delete emails in all inboxes using PowerShell?
Accepted answer
-
Vasil Michev 100.2K Reputation points MVP
2022-03-09T07:39:44.177+00:00