...
Code Block | ||||
---|---|---|---|---|
| ||||
<# YOU MUST CONNECT to Exchange Online as a Global Admin for this script to run properly. Connect-ExchangeOnline #> $domains = @( "ssuport.com", "supppot.com", "center-supports.com", "supoorts.com", "suporrt.com", "team-support.net", "supppot.net", "legal-user.com", "the-verification.com", "legals-team.com", "authenticatecenter.com", "ourlogin.co.uk", "mnminfo.com", "help-desc.com", "account-protector.com", "calendarsupdates.com", "appstatusupdate.com", "hr-updates.net", "itservicesector.com", "mailer-sender.com", "servicealerts.net", "status-pager.com", "nonreplies.com", "registerconfirmation.com", "altasian.net", "communitlyforums.com", "validation-service.net", "supplyservice.net", "shopping-card.net", "paymentserrvice.com", "online-store-service.com", "market-sales.net", "internal-service-updates.com", "infraupdates.com" ) # Prompt user to choose between adding or removing domains $addDomains = "" while ($addDomains -ne "a" -and $addDomains -ne "r") { $addDomains = Read-Host "Do you want to add (a) or remove (r) domains? (a/r)" $addDomains = $addDomains.Trim().ToLower() # Trim whitespace and convert to lowercase } function Write-ProgressHelper { param ( [int]$StepNumber, [string]$Message ) Write-Progress -Activity 'Updating SafeList' -Status $Message -PercentComplete (($StepNumber / $steps) * 100) } $script:steps = ([System.Management.Automation.PsParser]::Tokenize((Get-Content "$PSScriptRoot\$($MyInvocation.MyCommand.Name)"), [ref]$null) | Where-Object { $_.Type -eq 'Command' -and $_.Content -eq 'Write-ProgressHelper' }).Count $stepCounter = 0 # Get all active user type mailboxes Write-ProgressHelper -Message 'Getting mailboxes' -StepNumber ($stepCounter++) $Mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited $totalMailboxes = $Mailboxes.Count Write-Output "Total mailboxes: $totalMailboxes" $processedMailboxes = 0 # Configure junk email settings for each mailbox if ($addDomains -eq "a") { $JunkEmailConfig = @{ Add = "ssuport.com", "supppot.com", "center-supports.com", "supoorts.com", "suporrt.com", "team-support.net", "supppot.net", "legal-user.com", "the-verification.com", "legals-team.com", "authenticatecenter.com", "ourlogin.co.uk", "mnminfo.com", "help-desc.com", "account-protector.com", "calendarsupdates.com", "appstatusupdate.com", "hr-updates.net", "itservicesector.com", "mailer-sender.com", "servicealerts.net", "status-pager.com", "nonreplies.com", "registerconfirmation.com" $domains } } else { $JunkEmailConfig = @{ Remove = "ssuport.com", "supppot.com", "center-supports.com", "supoorts.com", "suporrt.com", "team-support.net", "supppot.net", "legal-user.com", "the-verification.com", "legals-team.com", "authenticatecenter.com", "ourlogin.co.uk", "mnminfo.com", "help-desc.com", "account-protector.com", "calendarsupdates.com", "appstatusupdate.com", "hr-updates.net", "itservicesector.com", "mailer-sender.com", "servicealerts.net", "status-pager.com", "nonreplies.com", "registerconfirmation.com" } }$domains } } # Configure junk email settings for each mailbox Write-ProgressHelper -Message 'Configuring junk email settings' -StepNumber ($stepCounter++) $i = 0 foreach ($Mailbox in $Mailboxes) { $MailboxIdentity = $Mailbox.PrimarySmtpAddress.ToString() Set-MailboxJunkEmailConfiguration -Identity $MailboxIdentity -TrustedSendersAndDomains $JunkEmailConfig $processedMailboxes++ if ($addDomains -eq "a") { Write-Progress -Id 1 -Activity "Working..." -status "Added: $i of $($Mailboxes.Count)" -percentComplete (($i / $Mailboxes.Count) * 100) $i++ } else { Write-Progress -Id 1 -Activity "Working..." -status "Removed: $i of $($Mailboxes.Count)" -percentComplete (($i / $Mailboxes.Count) * 100) $i++ } } Write-Output "Processed mailboxes: $processedMailboxes" |
...