Using Powershell To Whitelist Your Emails In M365 - KAMIND IT
Maybe your like
CMMC Compliance and Cybersecurity
- 503-726-5933

Another way you can add domains to a Whitelist in M365 is by using a script known as “PowerShell”. To do this, follow these steps:
1. Make use of this specific script:
- Param(
- [Parameter(Mandatory=$True,Position=1)]
- [string]$ruleName,
- [Parameter(Mandatory=$True)]
- [string]$domainListFilePath
- )
- #Read the contents of the text file into an array
- $safeDomainList = Get-Content $domainListFilePath
- #Create a new array and remove all text for each line up to and including the @ symbol, also remove whitespace
- $newSafeDomainList = @()
- $newSafeDomainList += foreach ($domain in $safeDomainList)
- {
- $tmpdomain = $domain -replace “.*@”
- $tmpdomain.trim()
- }
- #If the rule already exists update the existing allowed sender domains, else create a new rule.
- if (Get-TransportRule $ruleName -EA SilentlyContinue)
- {
- “Updating existing rule…”
- $safeDomainList = Get-TransportRule $ruleName |select -ExpandProperty SenderDomainIs
- $completeList = $safeDomainList + $newSafeDomainList
- $completeList = $completeList | select -uniq | sort
- set-TransportRule $ruleName -SenderDomainIs $completeList
- }
- else
- {
- “Creating new rule…”
- $newSafeDomainList = $newSafeDomainList | sort
- New-TransportRule $ruleName -SenderDomainIs $newSafeDomainList -SetSCL “-1”
- }
2. Using the “Notepad” feature in Word, type in your domains to be listed as follows:
nicedomain.com trusteddomain.com tachytelic.net [email protected]
3. Connect to the Exchange Online Portal using PowerShell. For instructions on how to do that, click on the below link:
https://docs.microsoft.com/en-us/powershell/exchange/connect-to-exchange-online-powershell?redirectedfrom=MSDN&view=exchange-ps
Run the script illustrated in Step #1 with these kinds of parameters:
.\Add365SafeDomains.ps1 -ruleName “Safe Domain List” -domainListFilePath “c:\domainlist.txt”
It is important to the note the following:
*If you are already using an existing rule, any duplicate domains are automatically purged;
*The domain list is thus sorted into an alphabetical order for easier reading in M365;
*If you a create a rule name that does not already exist, a new rule will thus be automatically created.
Recent Posts
- The One Business Resolution That Actually Sticks (Unlike Your Gym Membership)
- Dry January for Your Business: 6 Tech Habits to Quit Cold Turkey
- Stop Funding These 3 Tech Money Pits – Take Your Family To Hawaii Instead
- 2026 Tech Trends: What Small Businesses Should Actually Pay Attention To (And What You Can Ignore)
- The Business Owner’s Guide To Holiday Travel (That Won’t End In A Data Breach)
Categories
Categories Select Category AI Azure Blog Business Business Continuity CMMC Copilot Covid-19 Cybersecurity eTechTip KAMIND IT Microsoft Microsoft Teams Microsoft updates News Security Social Media UncategorizedArchives
Archives Select Month December 2025 October 2025 August 2025 July 2025 June 2025 May 2025 April 2025 March 2025 February 2025 January 2025 December 2024 November 2024 October 2024 September 2024 August 2024 July 2024 June 2024 May 2024 April 2024 March 2024 February 2024 December 2023 November 2023 October 2023 September 2023 August 2023 July 2023 June 2023 May 2023 April 2023 March 2023 February 2023 January 2023 December 2022 November 2022 October 2022 September 2022 August 2022 July 2022 June 2022 May 2022 April 2022 March 2022 February 2022 January 2022 December 2021 November 2021 October 2021 September 2021 August 2021 July 2021 June 2021 May 2021 April 2021 March 2021 February 2021 January 2021 December 2020 November 2020 October 2020 September 2020 August 2020 July 2020 June 2020 May 2020 April 2020 March 2020 February 2020 January 2020 December 2019 November 2019 October 2019 September 2019 August 2019 July 2019 June 2019 May 2019 April 2019 March 2019 February 2019 January 2019 December 2018 November 2018 October 2017 August 2017 June 2017 April 2017 July 2016 February 2016 January 2016 December 2015 November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 November 2014 September 2014 August 2014 July 2014
Contact Info
- 5200 Meadows Road Suite 150Lake Oswego, OR 97035
- Phone: 503-726-5933
Navigation
©2026 KAMIND IT All Rights Reserved. Privacy Policy Tag » Add Domain To Whitelist Office 365 Powershell
-
How To Whitelist A Domain In Office 365 - LazyAdmin
-
[SOLVED] Whitelisting Domain On Exchange Via Powershell
-
How To Bulk Whitelist Domains In Office 365 Using Powershell
-
Add A Domain To A Client Tenancy With Windows PowerShell For DAP ...
-
How Do I Whitelist A Domain In Office 365? - Holm Security
-
Whitelist Domains And Email Addresses On Exchange Server And ...
-
Add Your Domain Name To Trusted Senders For All Delegated Office ...
-
Whitelist A Domain In Office 365 Exchange Online | HowTo
-
How To Create A Whitelist On Office 365 - Ery Bilişim
-
Adding A Domain To Office 365 With PowerShell - MSB365
-
Whitelist Domain In Office 365 To Bypass SPAM Filtering - ALI TAJRAN
-
Bulk Import Of Whitelist Or Blacklists Llists Into O365 - PEI
-
Configure Anti-spam Policies In EOP - Microsoft-365-docs - GitHub
-
Importing Email Addresses & Domains To Blacklist In Office 365 ...