Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16a0301

Browse files
authoredMar 13, 2020
Update PurgeMessagesWithContentSearch.PS1
1 parent 4d59d3e commit 16a0301

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

‎PurgeMessagesWithContentSearch.PS1

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
# Some information to identify the messages we want to purge
99
$Sender = "badactor@badboys.com"
1010
$Subject = "Special Offer for you"
11+
# Date range for the search - make this as precise as possible
12+
$StartDate = "10-Mar-2020"
13+
$EndDate = "13-Mar-2020"
14+
$Start = (Get-Date $StartDate).ToString('yyyy-MM-dd')
15+
$End = (Get-Date $EndDate).ToString('yyyy-MM-dd')
16+
$ContentQuery = '(c:c)(received=' + $Start + '..' + $End +')(senderauthor=' + $Sender + ')(subjecttitle="' + $Subject + '")'
1117

1218
CLS
1319
If (Get-ComplianceSearch -Identity "Remove Offensive Information") {
1420
Write-Host "Cleaning up old search"
1521
Try {
16-
Remove-ComplianceSearch -Identity "Remove Offensive Information" -Confirm:$False -ErrorAction SilentlyContinue }
22+
$Status = Remove-ComplianceSearch -Identity "Remove Offensive Information" -Confirm:$False }
1723
Catch {
1824
Write-Host "We can't clean up the old search" ; break }}
1925

20-
New-ComplianceSearch -Name "Remove Offensive Information" -ContentMatchQuery "(Received:6-Mar-2020..14-Mar-2020) AND (From:$Sender) AND (Subject:$Subject)" -ExchangeLocation All -AllowNotFoundExchangeLocationsEnabled $True | Out-Null
26+
New-ComplianceSearch -Name "Remove Offensive Information" -ContentMatchQuery $ContentQuery -ExchangeLocation All -AllowNotFoundExchangeLocationsEnabled $True | Out-Null
2127

2228
Write-Host "Starting Search..."
2329
Start-ComplianceSearch -Identity "Remove Offensive Information" | Out-Null
@@ -28,7 +34,6 @@ While ((Get-ComplianceSearch -Identity "Remove Offensive Information").Status -n
2834
Sleep -Seconds 1 }
2935
$ItemsFound = (Get-ComplianceSearch -Identity "Remove Offensive Information").Items
3036

31-
3237
If ($ItemsFound -gt 0) {
3338
$Stats = Get-ComplianceSearch -Identity "Remove Offensive Information" | Select -Expand SearchStatistics | Convertfrom-JSON
3439
$Data = $Stats.ExchangeBinding.Sources |?{$_.ContentItems -gt 0}

0 commit comments

Comments
 (0)
Please sign in to comment.