r/PowerShell • u/StockMarketCasino • Jun 05 '26
Question Scripting adding countries to block inbound mail for Defender Anti-Spam policy
Set-HostedContentFilterPolicy -Identity "Default" -EnableRegionBlockList $true -RegionBlockList $CountriesToBlock
This command *should* use my 2-letter country code list variable and import it, but after it completes, when I go to check it in Defenter Anti-Spam policy, I get the error "Failed to Fetch Region Data". I've tried on PS ExchangeOnline 3.5.1 and 3.9.2, same issue.
Hit a wall here and cant seem to make sense of what its complaining about.
SOLVED: a handful of country codes that were not accepted by M365 were causing the import to complete, but fail on the web UI.
View all comments
Show parent comment
1
u/Overall-Ad4796 Jun 08 '26
the definition is perfectly fine and so are the ISO codes.
But I‘ve seen Defender having trouble mapping some smaller regions / territories such as AI and AX to their internal geolocation db - which causes this fetch error.
you could verify my assumption by
- first, setting -EnableRegionBlockList to $false and -RegionBlockList to $null ( -> to clear the UI error and start clean)
- and then using your command to re-enable it, but this time leaving out AI and AX.
Let me know how that goes….