Using Powershell To Whitelist Your Emails In M365 - KAMIND IT

KAMIND IT CMMC Compliance and CybersecurityGCC High Licensing
  • 503-726-5933
Blog Using Powershell to Whitelist Your Emails in M365 July 3, 2020 kamind Blog

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:

  1. Param(
  2. [Parameter(Mandatory=$True,Position=1)]
  3. [string]$ruleName,
  4. [Parameter(Mandatory=$True)]
  5. [string]$domainListFilePath
  6. )
  7. #Read the contents of the text file into an array
  8. $safeDomainList = Get-Content $domainListFilePath
  9. #Create a new array and remove all text for each line up to and including the @ symbol, also remove whitespace
  10. $newSafeDomainList = @()
  11. $newSafeDomainList += foreach ($domain in $safeDomainList)
  12. {
  13. $tmpdomain = $domain -replace “.*@”
  14. $tmpdomain.trim()
  15. }
  16. #If the rule already exists update the existing allowed sender domains, else create a new rule.
  17. if (Get-TransportRule $ruleName -EA SilentlyContinue)
  18. {
  19. “Updating existing rule…”
  20. $safeDomainList = Get-TransportRule $ruleName |select -ExpandProperty SenderDomainIs
  21. $completeList = $safeDomainList + $newSafeDomainList
  22. $completeList = $completeList | select -uniq | sort
  23. set-TransportRule $ruleName -SenderDomainIs $completeList
  24. }
  25. else
  26. {
  27. “Creating new rule…”
  28. $newSafeDomainList = $newSafeDomainList | sort
  29. New-TransportRule $ruleName -SenderDomainIs $newSafeDomainList -SetSCL “-1”
  30. }

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 Uncategorized

Archives

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 KAMIND_Logo_footer

Contact Info

  • 5200 Meadows Road Suite 150Lake Oswego, OR 97035
  • Phone: 503-726-5933
KAMIND IT

Navigation

©2026 KAMIND IT All Rights Reserved. Privacy Policy

Tag » Add Domain To Whitelist Office 365 Powershell