forked from msp4msps/Security
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlock Auto-FW.ps1
16 lines (12 loc) · 870 Bytes
/
Block Auto-FW.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Install-Module PowershellGet -Force
Update-Module PowershellGet
Set-ExecutionPolicy RemoteSigned
Install-Module -Name ExchangeOnlineManagement
Connect-ExchangeOnline
$externalTransportRuleName = "Block Auto-Forwarding"
$rejectMessageText = "To improve security, auto-forwarding rules to external email addresses have been disabled. Please contact your helpdesk if you want to create an exception."
$externalForwardRule = Get-TransportRule | Where-Object {$_.Identity -contains $externalTransportRuleName}
if (!$externalForwardRule) {
Write-Output "Rule for Auto-forwarding not found, creating Rule"
New-TransportRule -name "Block Auto-forwarding" -Priority 1 -SentToScope NotInOrganization -FromScope InOrganization -MessageTypeMatches AutoForward -RejectMessageEnhancedStatusCode 5.7.1 -RejectMessageReasonText $rejectMessageText
}