if (-NOT (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) { Install-Module -Name ExchangeOnlineManagement -Force } Import-Module ExchangeOnlineManagement $admin = Read-Host "Enter your Exchange admin email or UPN" Connect-ExchangeOnline -UserPrincipalName $admin # Define all safe sender domains $senders = @( 'ch-account-2fa.com', 'ch-contact-us.com', 'ch-login-created.com', 'ch-password-reset.com', 'ch-security-alert.com', 'cyberhoot.com', 'docunotice.com', 'messagecenters.net', 'securedinbox.net', 'notificationhub.net', 'filealert.org', 'secure-access.info', 'login-updates.com', 'updateportals.com', 'accountverifies.com', 'auth-check.page' ) # Get user mailboxes only $users = Get-User -ResultSize Unlimited | Where-Object {$_.RecipientTypeDetails -eq "UserMailbox"} foreach ($user in $users) { try { Write-Output "Adding trusted senders to $($user.UserPrincipalName)..." Set-MailboxJunkEmailConfiguration -Identity $user.UserPrincipalName -TrustedSendersAndDomains @{Add = $senders} } catch { Write-Warning "Failed to update $($user.UserPrincipalName): $_" } } Write-Output "Finished updating safe senders for all users!"