# Complete setup for creating a distribution group and then the Transport Rule alongside it. param( [Parameter(Mandatory=$false)] [string]$DistroGroupName = "GWStorageMonitoringUsers", [Parameter(Mandatory=$false)] [string]$RuleName = "Glasswall Attachment Processing Notice", [Parameter(Mandatory=$false)] [string]$Comments = "This rule adds a Glasswall processing notice banner to all inbound emails that include attachments for monitored email addresses.", # Mandatory in Standalone sets only [string]$ExchangeCertificatePath, [string]$ExchangeAppId, [string]$ExchangeOrganization, # Optional local/interactive login via UPN instead of cert [string]$UserPrincipalName, # Standalone switch รข present in Halo, assumed Standalone if absent [switch]$Halo ) if (-not $Halo) { Write-Host("Starting Glasswall Outlook Banner synchronization...") if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) { Write-Warning "EXO module not found. Installing..." Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force } if (-not (Get-Module -Name ExchangeOnlineManagement)) { Write-Verbose "Importing EXO module..." Import-Module ExchangeOnlineManagement } try { Get-OrganizationConfig -ErrorAction Stop | Out-Null Write-Host "Connected to Exchange Online" -ForegroundColor Green } catch { Write-Verbose "Not connected to Exchange Online. Initiating connection..." if ($UserPrincipalName) { Write-Host "Opening browser login for $UserPrincipalName..." Connect-ExchangeOnline -UserPrincipalName $UserPrincipalName ` -ShowBanner:$false } else { Write-Warning "No UserPrincipalName provided, falling back to certificate authentication. Please ensure certificate parameters are provided..." $parametersMissing = $false if (-not $ExchangeCertificatePath) { Write-Error "-ExchangeCertificatePath is required"; $parametersMissing = $true } if (-not $ExchangeAppId) { Write-Error "-ExchangeAppId is required"; $parametersMissing = $true } if (-not $ExchangeOrganization) { Write-Error "-ExchangeOrganization is required"; $parametersMissing = $true } if ($parametersMissing) { Write-Error "One or more Exchange parameters are missing - see previous errors. Alternatively, please provide a valid email login for UserPrincipalName" exit 1 } Write-Host "Connecting to Exchange Online via certificate authentication..." Connect-ExchangeOnline -AppId $ExchangeAppId ` -CertificateFilePath $ExchangeCertificatePath ` -Organization $ExchangeOrganization ` -ShowBanner:$false } Write-Host "Connected to Exchange Online" -ForegroundColor Green } } $disclaimerText = @"