«

»

Oct 25

Print this Post

Add Trusted Sender to All Users

This script will add a list of email addresses to the trusted senders list for all mailboxes in your organization.

Add Trusted Senders
Add Trusted Senders
Add_Trusted_Senders.zip
Version: 1
1.1 KiB
3 Downloads
Details

### Load Exchange Powershell Management Modules ###
Write-Host "Loading Exchange Management Powershell Modules"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010, Microsoft.Exchange.Management.PowerShell.Setup , Microsoft.Exchange.Management.Powershell.Support
#####

# Add all your trusted senders and domains to this Array
$orgList = @(“[email protected]”,”[email protected]”,”@trusteddomain.com”)

# Load all the mailboxes in your organization
$mbs = get-mailbox -ResultSize Unlimited

# Get the mailbox count and set some variables for use later
$count = $mbs.count
$i = 0

### Loop through all mailboxes in the organization and update the trusted senders list ###
foreach($mb in $mbs){
$userList = @()

### Display the progress – can be eliminated and won’t affect function
$i += 1
$mbName = $mb.Name
$pctComplete = [int] (($i / $count) * 100)
Write-Progress -Activity $mbName -Status “($i / $count) $pctComplete%” -PercentComplete $pctComplete
### ###

# Load this user’s Trusted senders list
$userListTemp = ($mb | Get-MailboxJunkEmailConfiguration).TrustedSendersAndDomains

# Filter out any duplicates in the user’s trusted senders list and shift the rest to lower case for matching later
foreach($sender in $userListTemp){ if($userList -notcontains $sender.ToLower()){ $userList += $sender.ToLower() } }

# The $changed variable will be used to decide if we are writing anything to the users
$changed = $false

### Loop through each sender in our
foreach($sender in $orgList){
# Shift the sender address to lower case
$lowerSender = $sender.ToLower()
# Check whether the user alreadh has this sender/domain in their trusted senders list
if($userList -notcontains $sender){
# If the user doesn not have this sender, add it and set $changed to $true
$changed = $true
$userList += $sender
}
}

# If the trusted senders list was changed, write the change back to the user.
if($changed -eq $true){
$mb | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains $userList -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
}
### ###

Permanent link to this article: https://www1.wperry.net/code/add-trusted-sender-to-all-users/

Leave a Reply

Your email address will not be published. Required fields are marked *