Security Policy Errors

Automatically Update Office 365 Blocked Domains from a Threat Feed

Phi Hung VoPhi Hung Vo Nov 14, 2026 868 views

Question details

The user wants to automatically update an Office 365 blocked-domain list from a changing threat feed.

Automatically Update Office 365 Blocked Domains from a 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.
Before you start

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.

Solution 1Recommended

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.

1
Prepare access and the policy

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.

2
Create the feed file

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.

3
Create the update script

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 }

4
Test and schedule the script

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.

Add threat-feed domains to an Exchange Online spam policy with PowerShell
Review policy scope: Confirm that the selected anti-spam policy applies to the intended recipients and that its priority is appropriate. Test mail flow before applying a large feed to production.
Free Microsoft Office alternative

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.

Review and organize threat-feed domain lists in spreadsheetsOpen and edit Microsoft Excel XLSX and Word DOCX filesUse familiar document and spreadsheet toolsWork with a free, lightweight Office suite
microsoft office alternative - wps office

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.