
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
testemailaddress@somedomain.com
3. Connect to the Exchange Online Portal using PowerShell. For instructions on how to do that, click on the below link:
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.


