I'm trying to use Exchange Online PowerShell to add a list of countries to the inbound region block list for the default Defender anti-spam policy:
Set-HostedContentFilterPolicy -Identity "Default" -EnableRegionBlockList $true -RegionBlockList $CountriesToBlock
My variable contains two-letter country codes, for example:
$CountriesToBlock = @("AO","AI","AX","AL","AD")
The command completes, but the country list appears empty in the policy, and the web interface shows "Failed to Fetch Region Data." I reproduced the issue with ExchangeOnlineManagement versions 3.5.1 and 3.9.2. What causes this, and how can I fix the import?
2 Answers
First, verify that the variable contains exactly the values you expect and check the existing policy before applying the update. For example, use Get-HostedContentFilterPolicy to inspect the current region block list. The list should be an array of valid two-letter country codes, such as @("CN","RU"). If the command accepts the input but the portal cannot load the region data, the problem may be one or more unsupported codes rather than the PowerShell syntax.
The issue was caused by a handful of unsupported country codes in the list. The policy update appeared to complete, but those invalid values caused the portal to fail when it tried to retrieve the region data. Remove the offending codes, run Set-HostedContentFilterPolicy again, and then refresh the policy page. The remaining valid codes imported normally.

The variable was formatted as an array of two-letter codes, but the list contained a few country codes that Microsoft 365 did not accept. Removing those invalid entries allowed the import to display correctly.