Manage Office 365 global spam filter

First, connect to your tenant

Get-HostedContentFilterPolicy |fl

We need to manage the AllowedSenderDomains  field.

Issue this command to see the situation …

Get-HostedContentFilterPolicy |fl AllowedSenderDomains

If you want to expant it do this:

Get-HostedContentFilterPolicy | select -ExpandProperty AllowedSenderDomains 

To filter it and show only the domains list use this command:

Get-HostedContentFilterPolicy | select -ExpandProperty AllowedSenderDomains | Select-Object @{Name=’Domain’;Expression={$_}}

And now, we can export it to a CSV file to edit..

This is the command:

Get-HostedContentFilterPolicy | select -ExpandProperty AllowedSenderDomains | Select-Object @{Name=’Domain’;Expression={$_}} | Export-Csv .\PermitDomainList.csv -NoType

Now, after you have edited your csv list, we are ready to import it again ….

Now Import the CSV with this command:

Create a variable :

$AllowedSenderDomainList = Import-Csv .\PermitDomainList.csv

ForEach ($AllowedSenderDomain in $AllowedSenderDomainList) {Set-HostedContentFilterPolicy “Default” -AllowedsenderDomains @{Add=$AllowedSenderDomain.name} -MatchSubDomains True}

Now we can check the results:

Get-HostedContentFilterPolicy | select -ExpandProperty AllowedSenderDomains


This is the official Microsoft link about this command

That’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *