Share via

Query on Content Search

Glenn Maxwell 13,491 Reputation points
2026-03-20T18:54:54.9266667+00:00

Hi all,

I have successfully deleted emails from regular user mailboxes using the syntax below.

$users = Import-Csv -Path "C:\temp\input.csv"
$searchName = "test-search"
$subject = "TESTMESSAGE"
$searchQuery = "subject:`"$subject`" AND (Received:2026-03-15..2026-03-16) AND (from:`"no-reply(at)mydomain.comm`")" 
New-ComplianceSearch -Name $searchName -ExchangeLocation $users.EmailAddress -ContentMatchQuery $searchQuery -AllowNotFoundExchangeLocationsEnabled $true
Start-ComplianceSearch -Identity $searchName
New-ComplianceSearchAction -SearchName "test-search" -Purge -PurgeType HardDelete -Force
Get-ComplianceSearchAction -Identity "test-search_Purge"

However, this only affected regular mailboxes. I now want to include all mailbox types—such as shared mailboxes, resource (room/booking) mailboxes, and Microsoft 365 group mailboxes—and delete the email across the entire tenant.

Could anyone guide me on the correct settings or configuration in Content Search to ensure all mailbox types are included and the emails are permanently deleted from the tenant?

Microsoft Security | Microsoft Purview

Answer accepted by question author
  1. Smaran Thoomu 34,795 Reputation points Microsoft External Staff Moderator
    2026-03-23T07:42:15.3433333+00:00

    Hi @Glenn Maxwell

    To include all mailbox types across the tenant (user, shared, resource, and Microsoft 365 group mailboxes) in your Content Search, you should target all Exchange mailboxes instead of using a CSV list.

    You can do this by using:

    -ExchangeLocation All
    

    Example:

    $searchName = "test-search"
    

    After confirming the search results, you can proceed with the purge:

    New-ComplianceSearchAction -SearchName $searchName -Purge -PurgeType HardDelete
    

    Important Considerations:

    • Always review search results before running purge
    • Mailboxes under retention or litigation hold may preserve deleted items
    • Microsoft 365 group mailboxes are included when using All
    • Items are permanently removed after Managed Folder Assistant processing
    • Teams messages returned by the search query are not deleted by purge

    Hope this helps. Please let me know if you have any questions.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.