Automatically Update Office 365 Blocked Domains from a Threat Feed
Question details
The user wants to automatically update an Office 365 blocked-domain list from a changing threat feed.

- Product
- Microsoft 365 Exchange Online Protection
- Device & OS
- not provided
- Scenario
- A company receives threat-feed domain lists and wants to apply them to an email spam policy without manually entering each domain.
- Observed behavior
- The desired result is a blocked-domain list that is updated automatically as the threat feed changes.
Identify the Exchange Online anti-spam policy to update and confirm that the threat feed can be exported as a trusted text file with one validated domain per line. Check the policy's blocked-domain limits and permissions, and test with a small list before scheduling production updates.
Add threat-feed domains to an Exchange Online spam policy with PowerShell
Use a script to add new domains from a text file, then schedule it with an appropriately authorized noninteractive connection.
This example adds domains but does not remove entries that disappear from the feed. It preserves existing policy entries rather than replacing the entire blocked-domain list.
For a fully synchronized list, track which domains the automation added and remove only those managed entries that are no longer in the feed. Do not automatically remove manually maintained entries.
Install the ExchangeOnlineManagement PowerShell module and identify the target policy with Get-HostedContentFilterPolicy. For unattended execution, configure an Entra app with Exchange.ManageAsApp permission, admin consent, a certificate, and an appropriate Exchange role.
Export validated domains to a local text file such as C:\Feeds\blocked-domains.txt, with one domain per line. Arrange for the trusted feed process to refresh this file before each scheduled run.
Save the following as a PowerShell script and replace the placeholders with your app ID, certificate thumbprint, tenant domain, and policy name: Connect-ExchangeOnline -AppId '<app-id>' -CertificateThumbprint '<thumbprint>' -Organization '<tenant>.onmicrosoft.com' try { $policy = Get-HostedContentFilterPolicy -Identity '<policy-name>' -ErrorAction Stop $domains = @(Get-Content 'C:\Feeds\blocked-domains.txt' -ErrorAction Stop | ForEach-Object { $_.Trim() } | Where-Object { $_ -and -not $_.StartsWith('#') } | Select-Object -Unique) $newDomains = @($domains | Where-Object { $_ -notin $policy.BlockedSenderDomains }) if ($newDomains.Count -gt 0) { Set-HostedContentFilterPolicy -Identity $policy.Identity -BlockedSenderDomains @{Add=$newDomains} -ErrorAction Stop } } finally { Disconnect-ExchangeOnline -Confirm:$false }
Run the script against a test policy with a small, verified feed, then inspect the result with Get-HostedContentFilterPolicy -Identity '<policy-name>'. Use your scheduler to run PowerShell with the script after the feed refreshes; ensure its execution account can access the certificate and feed file, and monitor errors and policy limits.

Evaluate mail-flow rules or a third-party security service
Consider another control if the feed needs integration or synchronization beyond a manageable spam-policy script.
Document Your Blocked-Domain Workflow in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for a smooth transition. Use it to document your threat-feed process or review domain lists; it does not manage Exchange Online policies.

Frequently Asked Questions
Does Office 365 automatically import a dynamic threat feed into the blocked-domain list?
There is no native dynamic threat-feed integration for this blocked-domain list. You can automate updates with Exchange Online PowerShell or evaluate a third-party email security service.
Will the sample script remove domains that leave the feed?
No. It only adds domains that are not already in the selected policy. To remove stale feed entries safely, maintain a record of domains added by the automation and remove only those managed entries.
How do I find the spam policy to update?
Connect to Exchange Online PowerShell and run Get-HostedContentFilterPolicy to list policies. Check the intended policy's scope and priority before using its name with Set-HostedContentFilterPolicy.
Why do I need an app and certificate for a scheduled update?
A scheduled task needs a noninteractive way to authenticate. Configure an Entra app with Exchange.ManageAsApp permission, admin consent, certificate access, and an appropriate Exchange role, then use those credentials with Connect-ExchangeOnline.




