param( [Parameter(Mandatory=$true)] [string[]]$Members, [Parameter(Mandatory=$false)] [string]$DistroGroupName = "GWStorageMonitoringUsers", # Exchange params â 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 } } try { foreach ($member in $Members) { Remove-DistributionGroupMember -Identity $DistroGroupName -Member $member -Confirm:$false -ErrorAction SilentlyContinue Write-Verbose "Success: Member was removed Distribution Group and will no longer receive monitoring banners" } } catch { Write-Warning "Some or all members were unable to be removed from the Distribution Group. $Error" }