365-PSScripts/Add-DMARCTransportRule.ps1
2023-12-18 18:18:35 +00:00

28 lines
854 B
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$LogonEmail = Read-Host "Enter Logon Email"
Connect-ExchangeOnline -UserPrincipalName $LogonEmail
#Internal Transport rule
$InternalRule = @{
Name = 'DMARC Reject - Internal'
HeaderContainsMessageHeader = 'Authentication-Results'
HeaderContainsWords = 'dmarc=fail action=oreject'
RejectMessageReasonText = 'Unauthenticated email is not accepted due to the domains DMARC policy'
RejectMessageEnhancedStatusCode = '5.7.1'
}
New-TransportRule @InternalRule -Mode Enforce -FromScope InOrganization
#External
$ExternalRule = @{
Name = 'DMARC SCL - External'
HeaderContainsMessageHeader = 'Authentication-Results'
HeaderContainsWords = 'dmarc=fail action=oreject'
SetSCL = 5
}
New-TransportRule @ExternalRule -Mode Enforce -FromScope NotInOrganization
Get-TransportRule
Disconnect-ExchangeOnline -Confirm:$false