Delete more than 10 items from a mailbox using Compliance Search

https://answers.microsoft.com/en-us/msoffice/forum/all/delete-more-than-10-items-from-a-mailbox-using/f28efa60-3766-4f50-af2d-e1f9be588931


Problem description: 

The tenant admin needs to delete more than 10 items that match certain criteria from a mailbox, with as little manual intervention as possible. 

Approach: 

From O365 Compliance Portal, you create a Compliance search targeting a single mailbox and configure it with the required query criteria to identify the items that must be deleted. 

You run the Compliance Search and inspect the list of returned items to confirm the proper search criteria has been used, and you observe the number of items is high. 

Challenge: 

Deleting items by using Compliance Search is currently limited to 10 items at one time, as mentioned in the ‘New-ComplianceSearchAction’ PowerShell article. 

Solution: 

Use a PowerShell script to automate the deletion of items in multiple batches of 10 items, as described below.

 

O365Troubleshooters is a module which is published over PowerShell Gallery containing tools to assist admins investigate issues and to automate tasks related to Office 365 workloads, and one of these tools is called ‘Compliance Search Bulk Delete Action’ which facilitates the deletion of items in multiple batches of 10 items for a selected Compliance Search that targets a single mailbox. 

IMPORTANT!

  • This is a sample script and sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

  • This tool is intended for Compliance Searches scoped for single mailbox only!

    Trying to adjust it for multiple mailboxes may lead to unforeseen issues, due to per tenant Compliance Search limits!

  • If there are no holds protecting the items or mailbox, there is the risk for these items to be purged with the next Managed Folder Assistant run, depending on the Single Item Recovery settings of the mailbox! Managed Folder Assistant runs automatically at any time between 1 to 7 days since its last execution.

  • If there are holds protecting the items or the mailbox, the items will be present under 'Recoverable Items' mailbox folder after deletion process. They will not be accessible to the user via email clients, but the tenant admin will be able to either restore them or find them using Compliance Search and export them as PST."

The logic of this script is:

  • Provide you with the option to select the Compliance Search which targets a single mailbox. It won’t allow Compliance Searches scoped for multiple mailboxes.

  • Displays the name of the selected search, number of items and their total size.

  • Verifies the Single Item Recovery (SIR) settings mailbox settings and displays warnings accordingly.

  • Reports remaining free space under ‘Recoverable Items’ and doesn’t allow to continue if there isn’t enough space.

  • Prompts for confirmation to proceed with deletion.

  • Limits the scope of the search to exclude the 'Recoverable Items', 'Purges', ‘DiscoveryHolds’ and 'Versions' folders, then refreshes the search. This step is needed, otherwise only the first batch of 10 items get deleted.

  • Loops the creation, execution and removal of compliance search actions of type purge in batches of 10 items, until all items are deleted. The removal of the compliance search action at the end of each batch is needed, otherwise only the first batch of 10 items get deleted.

  • Offers choice to keep or remove the 'Recoverable Items', 'Purges', ‘DiscoveryHolds’ and 'Versions' folders exclusion from the selected Compliance Search.

  • Offers choice to see the execution report in html format.

How to use the ‘Compliance Search Bulk Delete Action’ tool: 

Please follow the below steps: 

 

1. Run PowerShell as administrator

 

2. Install the O365troubleshooters module then import it: 

Install-Module O365Troubleshooters 

Import-Module O365Troubleshooters 

Image

3. Run ‘Start-O365Troubleshooters’ command then press any key to launch another PowerShell session with the tools menu. 

Image

4. Choose the ‘Compliance Search Bulk Delete Action’ tool by typing its corresponding number:

Image

5. Input the admin account username & password to connect to EXO & SCC 

Image

6. A window with all existing Compliance Searches will open, please select the search which targets a single mailbox and for which you need to delete the found items. 

Image

7. You will be presented with a summary of the selected search and prompted for confirmation to proceed with the selected search.

After confirmation, the script will update the selected search to exclude the 'Recoverable Items', 'Purges', ‘DiscoveryHolds’ and 'Versions' folders from its scope and will start deleting the items in batches of 10 items.

When finished, it will ask if you want to keep or remove the 'Recoverable Items', 'Purges', ‘DiscoveryHolds’ and 'Versions' folders exclusion from the selected Compliance Search, and it will ask if you wish to open the execution report.

 

Example for a mailbox with SIR disabled:

Image

Example for a mailbox with SIR enabled and ‘RetainDeletedItemsFor’ mailbox property set to 14 days:

Image

The execution report is saved locally, and the script will display its path as well. 

8. Example of an execution report: 

Image

Observations: 

  • Permissions required for the admin running the tool are mentioned in this article ‘Search for and delete email messages’.

  • The items deleted via Compliance Search Action remain available in folders under ‘Recoverable Items’ mailbox folder (excepting ‘Deletions’ folder), governed by the mailbox Single Item Recovery settings and holds applied. As long as they remain in those folders, the user cannot access them via email clients, but the admin can restore them, or can find and export them using Compliance Search.

  • Unindexed items and content from Microsoft Teams will not be processed.

Useful resources: 

Commenti

Post popolari in questo blog

How to reset an Office 365 install to the initial activation/install state

Manage Room Mailbox by using PowerShell

Come e quando smantellare i server Exchange in una distribuzione ibrida