Skip to content

Commit 50bf6a0

Browse files
committed
Remove the option to remove the rule and require the OrgName prefix
1 parent 4442d54 commit 50bf6a0

File tree

1 file changed

+17
-61
lines changed

1 file changed

+17
-61
lines changed

ExchangeOnline/New-EXOExternalDisclaimerTransportRule.ps1

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
Transport rule priority (0 = highest). Default: 0
1818
.PARAMETER RuleName
1919
Transport rule name. Default: "Security – Inbound External – Prepend Disclaimer"
20-
.PARAMETER Remove
21-
Remove the transport rule instead of creating/updating it
2220
.PARAMETER Disabled
2321
Create the rule in disabled state (safer for testing)
2422
.PARAMETER Mode
@@ -34,8 +32,6 @@
3432
.\New-EXOExternalDisclaimerTransportRule.ps1 -OrgPrefix "Contoso Corp"
3533
.EXAMPLE
3634
.\New-EXOExternalDisclaimerTransportRule.ps1 -OrgPrefix "ACME" -Priority 2 -WhatIf
37-
.EXAMPLE
38-
.\New-EXOExternalDisclaimerTransportRule.ps1 -OrgPrefix "MyOrg" -Remove -Confirm
3935
.EXAMPLE
4036
.\New-EXOExternalDisclaimerTransportRule.ps1 -OrgPrefix "MyOrg" -Disabled
4137
.EXAMPLE
@@ -88,9 +84,6 @@ param(
8884
[ValidateNotNullOrEmpty()]
8985
[string]$RuleName = "Security – Inbound External – Prepend Disclaimer",
9086

91-
[Parameter(HelpMessage = "Remove the transport rule instead of creating/updating it")]
92-
[switch]$Remove,
93-
9487
[Parameter(HelpMessage = "Create the rule in disabled state (safer for testing)")]
9588
[switch]$Disabled,
9689

@@ -140,14 +133,12 @@ function Test-ExchangeOnlineConnection {
140133
try {
141134
Get-OrganizationConfig -ErrorAction Stop | Out-Null
142135
Write-Verbose "Connected to Exchange Online"
143-
return $true
144136
} catch {
145137
if ($AutoConnect) {
146138
Write-Information "Not connected to Exchange Online. Attempting to connect..." -InformationAction Continue
147139
try {
148140
Connect-ExchangeOnline -ErrorAction Stop
149141
Write-Information "Successfully connected to Exchange Online" -InformationAction Continue
150-
return $true
151142
} catch {
152143
throw "Failed to connect to Exchange Online automatically: $($_.Exception.Message). Try running Connect-ExchangeOnline manually."
153144
}
@@ -165,50 +156,23 @@ function Write-ScriptBanner {
165156
[string]$RuleName,
166157
[int]$Priority,
167158
[string]$Mode,
168-
[switch]$Remove,
169159
[switch]$Disabled
170160
)
171161

172-
if ($Remove) {
173-
Write-Information "MODE: Remove Rule" -InformationAction Continue
174-
} else {
175-
Write-Information "MODE: Deploy/Update Rule" -InformationAction Continue
176-
}
177-
162+
Write-Information "MODE: Deploy/Update Rule" -InformationAction Continue
178163
Write-Information "Organization: $OrgPrefix" -InformationAction Continue
179164
Write-Information "Header Name: $HeaderName" -InformationAction Continue
180165
Write-Information "Rule Name: $RuleName" -InformationAction Continue
181166
Write-Information "Priority: $Priority" -InformationAction Continue
182-
Write-Information "Rule State: $(if ($Disabled -and -not $Remove) { 'Disabled' } else { 'Enabled' })" -InformationAction Continue
167+
Write-Information "Rule State: $(if ($Disabled) { 'Disabled' } else { 'Enabled' })" -InformationAction Continue
183168
Write-Information "Mode: $Mode" -InformationAction Continue
169+
Write-Information "Duplicate Prevention: Enabled (via $HeaderName header)" -InformationAction Continue
184170

185-
$HeaderSafePrefix = $OrgPrefix -replace '\s+', '' -replace '[^A-Za-z0-9]', ''
186-
if ($HeaderSafePrefix -match '^ATL$|^ATL') {
187-
Write-Warning "Note: 'ATL' is ArchiTech Labs' prefix - consider using your org's name for clarity"
171+
if ($Disabled) {
172+
Write-Warning "Rule will be created in DISABLED state for safe testing"
188173
}
189-
190-
if (-not $Remove) {
191-
Write-Information "Duplicate Prevention: Enabled (via $HeaderName header)" -InformationAction Continue
192-
if ($Disabled) {
193-
Write-Warning "Rule will be created in DISABLED state for safe testing"
194-
}
195-
if ($Mode -ne 'Enforce') {
196-
Write-Information "Progressive Enforcement: Rule will run in $Mode mode (safer for initial rollout)" -InformationAction Continue
197-
}
198-
}
199-
}
200-
201-
function Remove-ExternalDisclaimerRule {
202-
[CmdletBinding()]
203-
param([string]$RuleName)
204-
205-
$existing = Get-TransportRule -Identity $RuleName -ErrorAction SilentlyContinue
206-
207-
if ($existing) {
208-
Remove-TransportRule -Identity $RuleName -Confirm:$false -ErrorAction Stop
209-
Write-Information "Successfully removed transport rule: $RuleName" -InformationAction Continue
210-
} else {
211-
Write-Warning "Transport rule '$RuleName' does not exist - nothing to remove"
174+
if ($Mode -ne 'Enforce') {
175+
Write-Information "Progressive Enforcement: Rule will run in $Mode mode (safer for initial rollout)" -InformationAction Continue
212176
}
213177
}
214178

@@ -262,7 +226,7 @@ Install-RequiredModules -ModuleNames @('ExchangeOnlineManagement')
262226
Test-ExchangeOnlineConnection
263227

264228
# Display configuration banner
265-
Write-ScriptBanner -OrgPrefix $OrgPrefix -HeaderName $HeaderName -RuleName $RuleName -Priority $Priority -Mode $Mode -Remove:$Remove -Disabled:$Disabled
229+
Write-ScriptBanner -OrgPrefix $OrgPrefix -HeaderName $HeaderName -RuleName $RuleName -Priority $Priority -Mode $Mode -Disabled:$Disabled
266230

267231
# Banner HTML content (using single-quoted here-string to prevent variable expansion)
268232
$BannerHtml = @'
@@ -296,27 +260,19 @@ $BannerHtml = @'
296260
</table>
297261
'@
298262

299-
# Handle operations based on parameters
263+
# Deploy the rule
300264
try {
301-
if ($Remove) {
302-
if ($PSCmdlet.ShouldProcess($RuleName, "Remove transport rule")) {
303-
Remove-ExternalDisclaimerRule -RuleName $RuleName
304-
}
305-
} else {
306-
if ($PSCmdlet.ShouldProcess($RuleName, "Create/update transport rule")) {
307-
New-ExternalDisclaimerRule -RuleName $RuleName -Priority $Priority -HeaderName $HeaderName -HeaderValue $HeaderValue -BannerHtml $BannerHtml -Mode $Mode -Disabled:$Disabled
308-
}
265+
if ($PSCmdlet.ShouldProcess($RuleName, "Create/update transport rule")) {
266+
New-ExternalDisclaimerRule -RuleName $RuleName -Priority $Priority -HeaderName $HeaderName -HeaderValue $HeaderValue -BannerHtml $BannerHtml -Mode $Mode -Disabled:$Disabled
309267
}
310268

311269
# Display completion message
312-
if (-not $Remove) {
313-
Write-Information "Configuration complete!" -InformationAction Continue
314-
if ($Disabled) {
315-
Write-Warning "The rule '$RuleName' is created but DISABLED. Enable it when ready to activate."
316-
Write-Information "To enable: Set-TransportRule -Identity '$RuleName' -Enabled `$true" -InformationAction Continue
317-
} else {
318-
Write-Information "The rule '$RuleName' is now active with NO authentication exceptions." -InformationAction Continue
319-
}
270+
Write-Information "Configuration complete!" -InformationAction Continue
271+
if ($Disabled) {
272+
Write-Warning "The rule '$RuleName' is created but DISABLED. Enable it when ready to activate."
273+
Write-Information "To enable: Set-TransportRule -Identity '$RuleName' -Enabled `$true" -InformationAction Continue
274+
} else {
275+
Write-Information "The rule '$RuleName' is now active with NO authentication exceptions." -InformationAction Continue
320276
}
321277
} catch {
322278
Write-Error "Failed to configure transport rule: $($_.Exception.Message)"

0 commit comments

Comments
 (0)