I am looking for a powershell script to purge my email of over 185,000 emails in Deleted Items and 190,000 in Drafts. Please is there any powershell script I could use to accomplish such a task? The Email is hosted on Microsoft Outlook (Office 365), I have ransacked the internet in everyway i can, maybe I am not using the correct Keywords.
2 Answers
Did you try https://docs.microsoft.com/en-us/microsoft-365/compliance/search-for-and-delete-messages-in-your-organization?view=o365-worldwide Or it should done from end-user side?
![](../../users/profiles/140751.webp)
- 69
- 4
Agree with Ziemek, you could search the emails with specific conditions in the Office 365 Security & Compliance and purge these emails with the command " New-ComplianceSearchAction -SearchName "SearchName" -Purge -PurgeType "HardDelete/SoftDelete" ".
However, before searching and purging, you need add your admin account as a member of the eDiscovery Manager(Create and run a Content Search) and Organization Management(Delete messages) role groups:
Then continue to search and purge. More details about the progress: OFFICE 365 – DELETING AN EMAIL, hope it helpful to you.
![](../../users/profiles/543434.webp)
- 1,323
- 1
- 3
- 4
-
What i want is to empty the Deleted Items folder completely. I am running this Search-Mailbox -Identity johndoe@test.com -SearchDumpsterOnly -TargetMailbox "Deleted Items" -TargetFolder "Deleted Items" -DeleteContent, but its saying Search-Mailbox : The term 'Search-Mailbox' is not recognized as the name of a cmdlet, – Hamed Apr 27 '20 at 07:31
-
According to the official document "https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/search-mailbox?view=exchange-ps", you need add your admin account as a member in the "Organization Management" role group(permissions > admin roles). – Ivan_Wang Apr 27 '20 at 07:46
-
If the above setting is fine, you could check whether you connected to Exchange PowerShell properly(Connect to Exchange Online PowerShell: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps#connect-to-exchange-online). – Ivan_Wang Apr 27 '20 at 07:48
-
In addition, to delete emails in the Drafts and Deleted Items, you could press "Ctrl" + "A", then right-click any one item and click "Delete". – Ivan_Wang Apr 27 '20 at 09:34
-
Hi, it's been long time, is there any progress? If the problem has been fixed, you could mark the best answer to help more people. Have a good day:) – Ivan_Wang Apr 30 '20 at 09:43