Whitelisting

How can I use PowerShell to add emails to user's Safe Sender list?

Before proceeding with this guide, ensure you have gone through the complete requirements in this article:
https://support.holmsecurity.com/knowledge/how-do-i-whitelist-a-domain-in-office-365

This PowerShell method goes through every mailbox in your Microsoft 365 tenant and adds several specific email addresses to each user’s Safe Senders list. 

Version-Safe Script

Description of what the script does for you:

  • Detects whether you’re connected to Exchange Online or on-prem.

  • Adds your trusted simulation sender addresses only if not already present.

  • Remember to edit and change the $trustedSenders to the adresses of the domain category you plan to use.

Download here: Add_trusted_sender_VersionSafe.ps1


Notes for Administrators

  • Permissions: Requires the exchange administrator role.

  • Safe to re-run: The script checks existing entries and avoids duplicates.

  • Scope: Applies only to existing mailboxes — re-run periodically or through a scheduled task for new users.

 

Connecting to Exchange Online

If you haven’t connected your PowerShell session yet, run the following command before initiating the script:

Install-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName admin@holmsecurity.com

Swap to your admin account e-mail address before running.

Compatibility Overview

Microsoft Email System Supported? How to Run Notes
Exchange Online (Microsoft 365)          Yes Connect via Exchange Online PowerShell (Connect-ExchangeOnline) Fully supported.
Exchange Server 2019 / 2016 / 2013 (on-prem)          Yes Run in the Exchange Management Shell on the server or via remote PowerShell. Requires admin rights on the Exchange server.
Exchange Server 2010        Limited Run in Exchange Management Shell Limited support; deprecated.
Exchange 2007 or older           No N/A Cmdlet not available.
Hybrid (on-prem + cloud) Yes (with two runs) Run once per environment Must connect to each environment separately.