if (-NOT (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) { Install-Module -Name ExchangeOnlineManagement } Import-Module ExchangeOnlineManagement $admin = Read-Host "Exchange admin email or UPN" Connect-ExchangeOnline -UserPrincipalName $admin $users = Get-User $senders = 'ch-account-2fa.com', 'ch-contact-us.com', 'ch-login-created.com', 'ch-password-reset.com', 'ch-security-alert.com', 'cyberhoot.com' #add safe senders here, in quotes and comma-separated foreach($user in $users){ $out = 'Adding Trusted Senders to {0}' -f $user.UserPrincipalName Write-Output $out Set-MailboxJunkEmailConfiguration $user.UserPrincipalName -TrustedSendersAndDomains @{Add=$senders} } Write-Output "Finished!"