A unified data governance solution that helps manage, protect, and discover data across your organization
Hi Roger Roger,
it sounds like you want to:
- Find every Compliance Search and its associated Compliance Search Action that was created by ******@contoso.com
- Export those objects to CSV (for auditing or records)
- 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):
- Grab all searches created by user12. Export searches for your records
$searches = Get-ComplianceSearch | Where-Object { $_.CreatedBy -eq '******@contoso.com' }
- Export searches for your records
$searches |
Select-Object Name, Status, CreatedBy, CreatedDate |
Export-Csv C:\Temp\User1_ComplianceSearches.csv -NoTypeInformation
- Grab all search-actions created by 4. Export actions for your records
user1
$actions = Get-ComplianceSearchAction | Where-Object { $_.CreatedBy -eq '******@contoso.com' }
- Export actions for your records
$actions |
Select-Object Identity, Action, SearchName, CreatedBy, CreatedDate |
Export-Csv C:\Temp\User1_SearchActions.csv -NoTypeInformation
- Remove all actions (must remove actions before deleting searches)
$actions | ForEach-Object {
Remove-ComplianceSearchAction -Identity $_.Identity -Confirm:$false
}
- 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:$falseto suppress confirmation prompts in a script, or omit it if you want to approve each deletion manually.
Hope this helps!
Reference list
- New-ComplianceSearch: https://learn.microsoft.com/powershell/module/exchangepowershell/new-compliancesearch?view=exchange-ps
- Get-ComplianceSearch: https://learn.microsoft.com/powershell/module/exchangepowershell/get-compliancesearch?view=exchange-ps
- Remove-ComplianceSearch: https://learn.microsoft.com/powershell/module/exchangepowershell/remove-compliancesearch?view=exchange-ps
- Get-ComplianceSearchAction: https://learn.microsoft.com/powershell/module/exchangepowershell/get-compliancesearchaction?view=exchange-ps
- Remove-ComplianceSearchAction: https://learn.microsoft.com/powershell/module/exchangepowershell/remove-compliancesearchaction?view=exchange-ps Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help. Please do not forget to "Accept Answer" and "up-vote" wherever the information provided helps you, as this can be beneficial to other community members.