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=$} -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!


  1. I wish this worked.

    When trying to use this command.

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

    I get this result.

    Cannot process argument transformation on parameter ‘AllowedSenderDomains’. Cannot convert value
    “System.Collections.Hashtable” to type “Microsoft.Exchange.Data.MultiValuedProperty`1[System.String]”. Error:
    “MultiValuedProperty collections cannot contain null values.


Leave a Reply

Your email address will not be published.