Skip to main content

[PowerShell] How do I whitelist in Microsoft Exchange and Microsoft Defender?

K
Written by Karthek S
Updated yesterday

To ensure seamless delivery of Right-Hand’s cybersecurity training and phishing simulation emails, we now provide a fully automated PowerShell script that configures your Microsoft 365 environment.

Once downloaded and executed, the script ensures our emails bypass spam filtering, clutter filtering, Safe Links, and Safe Attachments processing, helping prevent delivery issues and reducing setup time, while preserving existing policies to avoid conflicts.

Requirements

  • Operating System: Windows (Professional or Server editions)

  • Tool: PowerShell (must be run as Administrator)

  • Credentials: A valid Office 365 account

  • Authorization: Access to Exchange Online

Roles that would be required to execute operations:

  • Global Administrator

  • Compliance Management

  • Security Administrator

Note: The Office 365 user executing this script should be a “Global Administrator” or one of the above-listed roles.

Mandatory step:

You can ask for the custom header, which is associated to your company tenant in cyberready from your customer success manager. Alternatively you can mail to [email protected] to get the same. The header has the following format:
X-RHS-TID-<unique hash>

Add the custom header value to the RightHand-Whitelist-Config.txt

Microsoft Exchange and Microsoft Defender Whitelisting

How to Use the PowerShell Script

  • Extract the Script

    • Download the provided ZIP file: Right-Hand-Whitelisting.zip

    • Right-click the ZIP file and select "Extract All..."

    • Choose a location you can easily find later (for example: D:\Right-Hand-Whitelisting.zip\)

    • Make sure all files are fully extracted and accessible in the selected folder.

  • Open PowerShell as an Administrator

    • Click the Start menu and type PowerShell in the search bar.

    • Right-click Windows PowerShell, then choose Run as Administrator.

    • In the PowerShell window, navigate to the folder where you extracted the script. For example:

    cd 'D:\Right-Hand-Whitelisting.zip\'

  • Run the commands below separately to unblock the file.

  • Add the path where files are downloaded.

    Unblock-File -Path .\Right-Hand-Whitelisting.zip 
    Unblock-File -Path .\RightHand-Whitelist-Config.txt

Execute the Script

  • In the PowerShell window (with Administrator rights), run the script.

.\IP_Whitelisting.ps1
  • By default, the script will:

  • Use the IP, domain list and custom header from the file RightHand-Whitelist-Config.txt, which is included in the extracted ZIP package.

  • Authentication

    • When you run the script, you’ll be prompted to sign in with your Office 365 credentials.

    • If your account uses Multi-Factor Authentication (MFA), you’ll also need to complete an extra verification step, such as:

    • Entering a 6-digit code from the Microsoft Authenticator app

    • Approving a text message or mobile notification sent to your registered device.

  • Script Execution Time

    • The script usually completes within 3 to 4 minutes, depending on the number of domains being processed.

    • When the script runs successfully, you'll see confirmation messages displayed in the PowerShell window.

Conclusion

This PowerShell script streamlines whitelisting Right-Hand IPs and domains in Microsoft Exchange and Defender.

✅ Use the correct Office 365 credentials when prompted.

✅ Verify the updated allow policy in the Microsoft Exchange admin center or Microsoft 365 Security Center after running the script.

Did this answer your question?