-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathThirdPartySecurityMailFlow.ps1
More file actions
233 lines (204 loc) · 11.1 KB
/
ThirdPartySecurityMailFlow.ps1
File metadata and controls
233 lines (204 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
##
#<#
#.SYNOPSIS
# Reconfigure Third-Paty outbound connector (Mimecast, Proofpoint, Barracuda, or other) to be managed by a Transport Rule
#.DESCRIPTION
# This is designed to reconfigure Third-Paty outbound connector (Mimecast, Proofpoint, Barracuda, or other) to be managed by a Transport Rule.
# This is achieved by achieving the configuration described in the article below, but through PowerShell.
# https://support.exclaimer.com/hc/en-gb/articles/4405851491101
#
# Please refer to the REQUIREMENTS for the information needed to run this script correctly.
#.NOTES
# Email: helpdesk@exclaimer.com
# Date: 8th August 2024
#.PRODUCTS
# Exclaimer Cloud - Signatures for Office 365
#.REQUIREMENTS
# - The PowerShell "ExchangeOnlineManagement" module, will propmt to install if not present
# - Global Administrator Account
#.HISTORY
# 1.0 - Changes Outbound Connector usage
# - Configures a Transport Rule to manage that connector
# - Ensures the Transport Rule "Identify messages to send to Exclaimer Cloud" is configured to "Stop processing more rules"
# - This will ensure that your emails are processed through Exclaimer before being routed by other Transport Rules.
##>
#Getting Exchange Online Module
function infomative {
Write-Host "`nThis script is to be used only if you use a Third-Party Security Solution such as`
Mimecast, Proofpoint, Barracuda, or other, which you route your ""Outbound"" emails through.`
Only use it if you have connector configured to route emails from ""O365"" to ""Third-Party Security Solution (Mimecast, Proofpoint, Barracuda, etc)""`
`n`nFor more information, see article: 'https://support.exclaimer.com/hc/en-gb/articles/4405851491101'`n" -ForegroundColor Yellow
Write-Host "`nThis is NOT required if you use any of the Third-Party solutions for ""Inbound"" emails only.`n" -ForegroundColor RED
doContinue
}
function doContinue {
$doContinue = Read-Host "Would you like to continue? (y/n)"
if ($doContinue -eq "y" -OR $doContinue -eq "Y"){
Write-Host "Checking if require PowerShell Module is installed...." -ForegroundColor Yellow
checkExchangeOnlineModule
}
else
{
Write-Host "Will now disconnect and exit..." -ForegroundColor Red
endSession
}
}
function checkExchangeOnlineModule {
if (Get-Module -ListAvailable -Name ExchangeOnlineManagement) {
Write-Host "`nThe 'ExchangeOnlineManagement'PowerShell Module is already installed, lets sign in as the Global Admin...`n" -ForegroundColor Green
modernAuthConnect
}
else {
$askModInstall = read-Host("Would you like to install the Powershell 'ExchangeOnlineManagement' and continue? N/y")
if ($askModInstall -eq "n" -or $askModInstall -eq "N") {
Write-Host "`nCannot continue without the 'ExchangeOnlineManagement'PowerShell Module, will now Exit." -ForegroundColor Red
Exit
} else {
Write-Host "`nContinue and install the 'ExchangeOnlineManagement'PowerShell Module before continuing..." -ForegroundColor Green
pause
Install-Module ExchangeOnlineManagement -Scope CurrentUser
modernAuthConnect
}
}
}
function modernAuthConnect {
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
}
function gatherInfo {
$global:provider = Read-Host ("Who is your Email Security provider? (i.e Barracuda, Mimecast, Proofpoint, etc...)")
$global:outboundConnectorName = Read-Host ("What is the full and exact name of the Outbound connector for $global:provider)?")
Write-Host "`nThird-party provider......: $global:provider" -ForegroundColor Green
Write-Host "Connector name............: $global:outboundConnectorName" -ForegroundColor Green
thirdPartyProvider
}
function thirdPartyProvider {
$outboundConnector = Get-OutboundConnector -Identity $global:outboundConnectorName | Select-Object Name,Identity,Enabled,SmartHosts,IsTransportRuleScoped -ErrorAction SilentlyContinue
$thirdPartyTransportRule = Get-TransportRule | Where {$_.RouteMessageOutboundConnector -eq $global:outboundConnectorName}
$exclaimerTransportRule = Get-TransportRule | Where {$_.Name -like "Identify messages to send to Exclaimer Cloud"}
$global:thirdPartyTransportRuleName = $thirdPartyTransportRule.Name
$global:thirdPartyTransportRulePriority = $thirdPartyTransportRule.Priority
$global:exclaimerTransportRuleName = $exclaimerTransportRule.Name
$global:exclaimerTransportRulePriority = $exclaimerTransportRule.Priority
$global:exclaimerTransportRuleStopMoreRules = $exclaimerTransportRule.StopRuleProcessing
if ($outboundConnector){ # If a connector is found
Write-Host "`nConnector found...`n" -ForegroundColor Yellow
if ($outboundConnector.IsTransportRuleScoped -ne $False){ #If already managed by a Transport Rule
Write-Host "`nConnector is already managed by a Transport Rule" -ForegroundColor Green
IsTransportRuleScoped
}
else #If not managed by a Transport Rule
{
notIsTransportRuleScoped
}
}
else # If a connector is not found
{
Write-Host "`nNo connector was found by the name provided...`nYou can choose to continue (y) to try again, or not (n) to end this session. " -ForegroundColor Yellow
doTryAgain
}
}
function IsTransportRuleScoped {
Write-Host "This connector is already managed by a transport rule ""$thirdPartyTransportRule""." -ForegroundColor Green
if ($global:thirdPartyTransportRulePriority -gt $global:exclaimerTransportRulePriority){
Write-Host "No further action required." -ForegroundColor Green
endSession
}
else {
Write-Host "`nBut the order (priority) of the Transport Rules is not correct..." -ForegroundColor Red
Write-Host "Please update the Transport Rule ""$thirdPartyTransportRule"" so that it is of lower priority (higher number) `nthan the Transport Rule ""Identify messages to send to Exclaimer Cloud""." -ForegroundColor Red
Write-Host "`nThe Transport Rule ""$global:thirdPartyTransportRuleName"" is currently priority ""$global:thirdPartyTransportRulePriority""" -ForegroundColor Red
Write-Host "The Transport Rule ""$global:exclaimerTransportRuleName"" is currently priority ""$global:exclaimerTransportRulePriority""" -ForegroundColor Yellow
}
}
function notIsTransportRuleScoped {
Write-Host "`nConnector is not managed by a Transport Rule" -ForegroundColor Red
Write-Host "`nThe configuration of the connector $global:outboundConnectorName needs to be updated, so it can be managed by a Transport Rule..." -ForegroundColor Yellow
$doUpdateConnector = Read-Host "Would you like to continue? (y/n)"
if ($doUpdateConnector -eq "y" -OR $doUpdateConnector -eq "Y"){
updateOutboundConnector
}
else
{
endSession
}
}
function updateOutboundConnector {
Write-Host "`n============ Updating the connector '$global:outboundConnectorName'...." -ForegroundColor Yellow
Set-OutboundConnector -Identity $global:outboundConnectorName `
-IsTransportRuleScoped $True `
-RecipientDomains @() `
-Enabled $True `
-Comment $cn_comment
Write-Host "`n============ Connector '$global:outboundConnectorName' now updated." -ForegroundColor Green
createThirdPartyTR
}
function createThirdPartyTR {
Write-Host "`n============ Creating Transport Rule for connector '$global:outboundConnectorName'...." -ForegroundColor Yellow
New-TransportRule -Name "Route emails through $global:provider" `
-Mode Enforce `
-RuleErrorAction Ignore `
-FromScope InOrganization `
-SentToScope NotInOrganization `
-RouteMessageOutboundConnector $global:outboundConnectorName `
-SenderAddressLocation Envelope `
-RuleSubType None `
-UseLegacyRegex $false `
-HasNoClassification $false `
-AttachmentIsUnsupported $false `
-AttachmentProcessingLimitExceeded $false `
-AttachmentHasExecutableContent $false `
-AttachmentIsPasswordProtected $false `
-ExceptIfHasNoClassification $false `
-Comments $tr_comment
Write-Host "`n============ Transport Rule for connector '$global:outboundConnectorName' successfully created." -ForegroundColor Green
if ($global:provider -like "Barracuda") {
Write-Host "`n============ $global:provider does not support Out of Office emails..." -ForegroundColor Yellow
Write-Host "`n============ Updating the Transport Rule ""Route emails through $global:provider""..." -ForegroundColor Yellow
excludeAutomaticEmails
}
}
function excludeAutomaticEmails {
Set-TransportRule -Identity "Route emails through $global:provider" `
-ExceptIfMessageTypeMatches "OOF"
Write-Host "`n============ Successfully updated Transport Rule ""Route emails through $global:provider"" to exclude Out of Office emails...." -ForegroundColor Green
}
function checkExclTR {
if ($global:exclaimerTransportRuleStopMoreRules -eq $True) {
Write-Host "`nThe Transport Rule ""Identify messages to send to Exclaimer Cloud"" is correctly configured." -ForegroundColor Green
}
else {
Write-Host "============ The Transport Rule ""Identify messages to send to Exclaimer Cloud"" is not correctly configured to stop processing more rules..." -ForegroundColor Yellow
Write-Host "============ Updating Transport Rule ""Identify messages to send to Exclaimer Cloud"" to stop processing more rules...`n============ This will ensure that your emails are processed through Exclaimer before being routed by other Transport Rules...." -ForegroundColor Yellow
Set-TransportRule -Identity "Identify messages to send to Exclaimer Cloud" `
-StopRuleProcessing $True
Write-Host "============ Successfully updated Transport Rule ""Identify messages to send to Exclaimer Cloud"", now correctly configured to stop processing more rules." -ForegroundColor Green
}
}
function doTryAgain {
$doTryAgain = Read-Host "Would you like to try again? (y/n)"
if ($doTryAgain -eq "y" -OR $doTryAgain -eq "Y"){
gatherInfo
}
else
{
Write-Host "Will now disconnect and exit." -ForegroundColor Red
endSession
}
}
function endSession {
# Disconnecting from Exchange Online
Write-Host "`nWill now disconnect and exit." -ForegroundColor Yellow
Disconnect-ExchangeOnline -Confirm:$false
Write-Host "Session Ended`n" -ForegroundColor Red
Start-Sleep -Seconds 5
Exit
}
# Comments
$date = (Get-Date -Format "dd/MM/yyyy")
$tr_comment = "Created by Exclaimer Support PowerShell script on $date `nRoutes messages through the connector '$global:outboundConnectorName'"
$cn_comment = "Updated by Exclaimer Support PowerShell script on $date `nThis connector is now managed by Transport Rule ""Route emails through $provider"""
infomative
gatherInfo
checkExclTR
endSession