Share via

New-ComplianceSearch

Roger Roger 7,511 Reputation points
2026-03-23T06:46:47.5233333+00:00

Hi All,

I have used the PowerShell cmdlets New-ComplianceSearch and New-ComplianceSearchAction to search for and delete emails. I can see these searches listed under Compliance Search. I would like to delete these searches. For example, if my account is user1(at)contoso.com, I want to export all Compliance Searches and their associated actions created by this user(user1), and then delete them.

Could you please guide me with the appropriate PowerShell syntax to:

Identify all New-ComplianceSearch and New-ComplianceSearchAction objects related to user1(at)contoso.com

Delete those searches and their corresponding actions

Microsoft Security | Microsoft Purview
0 comments No comments

3 answers

Sort by: Most helpful
  1. SAI JAGADEESH KUDIPUDI 1,600 Reputation points Microsoft External Staff Moderator
    2026-03-25T15:06:57.6+00:00

    Hi Roger Roger,
    it sounds like you want to:

    1. Find every Compliance Search and its associated Compliance Search Action that was created by ******@contoso.com
    2. Export those objects to CSV (for auditing or records)
    3. Delete the search actions first, then delete the searches themselves

    Here’s a PowerShell snippet you can use in Security & Compliance PowerShell (you’ll need the appropriate permissions—Discovery Management or equivalent):

    1. Grab all searches created by user12. Export searches for your records
    $searches = Get-ComplianceSearch | Where-Object { $_.CreatedBy -eq '******@contoso.com' } 
    
    1. Export searches for your records
    $searches |
    Select-Object Name, Status, CreatedBy, CreatedDate |
      Export-Csv C:\Temp\User1_ComplianceSearches.csv -NoTypeInformation 
    
    1. Grab all search-actions created by 4. Export actions for your records
    user1
    $actions = Get-ComplianceSearchAction | Where-Object { $_.CreatedBy -eq '******@contoso.com' }
    
    1. Export actions for your records
    $actions |
      Select-Object Identity, Action, SearchName, CreatedBy, CreatedDate |
      Export-Csv C:\Temp\User1_SearchActions.csv -NoTypeInformation
    
    1. Remove all actions (must remove actions before deleting searches)
    $actions | ForEach-Object {
        Remove-ComplianceSearchAction -Identity $_.Identity -Confirm:$false
    }
    
    1. Remove all searches
    $searches | ForEach-Object {
        Remove-ComplianceSearch -Identity $_.Name -Confirm:$false
    }
    

    A few notes:

    • You filter on the CreatedBy property, which shows who ran the New-ComplianceSearch or New-ComplianceSearchAction cmdlet.
    • Always remove search actions first; if you delete the search before its action, the action cmdlet may fail.
    • Use -Confirm:$false to suppress confirmation prompts in a script, or omit it if you want to approve each deletion manually.

    Hope this helps!

    Reference list


  2. Prathista Ilango 1,065 Reputation points Microsoft Employee
    2026-03-23T20:54:11.6133333+00:00

    Hello Roger Roger,

    To retrieve existing Compliance Searches and remove them, you can use the following PowerShell cmdlets:

    1. Get-ComplianceSearch – Get-ComplianceSearch (ExchangePowerShell) | Microsoft Learn
    2. Remove-ComplianceSearch – Remove-ComplianceSearch (ExchangePowerShell) | Microsoft Learn

    To identify related operations (such as exports), you may need to refer to the Microsoft Purview eDiscovery APIs via Microsoft Graph. The documentation below outlines how to connect and query eDiscovery case data, including scenarios that use app-only access:

    https://learn.microsoft.com/en-us/purview/edisc-ref-api-guide#connecting-to-microsoft-graph-api-using-app-only-access

    If your requirement is to correlate searches with their associated actions (for example, exports) and perform cleanup, this may require custom scripting that combines these two. This approach might help surface the information you’re looking for.

    Hope this helps!

    If you found the information above helpful, please Click Yes. This will assist others in the community who encounter a similar issue, enabling them to quickly find the solution and benefit from the guidance provided.

    0 comments No comments

  3. Q&A Assist
    2026-03-23T06:46:57.8833333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Compliance searches and their purge actions are just compliance search and compliance search action objects. They can be listed and removed with the corresponding Get- and Remove- cmdlets. The context provided covers creating and purging content, but does not include syntax or properties for filtering or deleting the search and action objects themselves, so no supported PowerShell syntax can be given based on this context.


    References:

    0 comments No comments

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.