-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho365-AntiPhish-DeleteSilently.ps1
20 lines (16 loc) · 1.12 KB
/
o365-AntiPhish-DeleteSilently.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Full credit to - https://gcits.com/knowledge-base/warn-users-external-email-arrives-display-name-someone-organisation/
# Modified to just drop the message silently rather than prefixing a warning to it as the original script above does
# Needs to be run each time users are added or removed from tenancy; $displayNames are generated by this script.
# See link above for options to automate
$ruleName = "Delete e-mails from External Senders with matching display names"
Connect-ExchangeOnline
$rule = Get-TransportRule | Where-Object {$_.Identity -contains $ruleName}
$displayNames = (Get-Mailbox -ResultSize Unlimited).DisplayName
if (!$rule) {
Write-Host "Rule not found, creating rule" -ForegroundColor Green
New-TransportRule -Name $ruleName -Priority 0 -FromScope "NotInOrganization" -HeaderMatchesMessageHeader From -HeaderMatchesPatterns $displayNames -DeleteMessage $true
}
else {
Write-Host "Rule found, updating rule" -ForegroundColor Green
Set-TransportRule -Identity $ruleName -Priority 0 -FromScope "NotInOrganization" -HeaderMatchesMessageHeader From -HeaderMatchesPatterns $displayNames -DeleteMessage $true
}