Monday, June 25, 2018

Configuring an Office 365 SPAM filtering policy with PowerShell

I recently wrote an article that shows you how to configure the spam policy in Office 365 using the web interface. If you missed that you can find it here:

Configuring an Office 365 SPAM filtering policy

Doing this multiple times via the web interface is a lot of work. A better approach is to use PowerShell. So once, how have connected to Exchange Online PowerShell, run these two commands:

$policyparams = @{
"name" = "Configured Policy";
'Bulkspamaction' =  'movetojmf';
'bulkthreshold' =  '7';
'highconfidencespamaction' =  'movetojmf';
'inlinesafetytipsenabled' = $true;
'markasspambulkmail' = 'on';
'increasescorewithimagelinks' = 'off'
'increasescorewithnumericips' = 'on'
'increasescorewithredirecttootherport' = 'on'
'increasescorewithbizorinfourls' = 'on';
'markasspamemptymessages' ='on';
'markasspamjavascriptinhtml' = 'on';
'markasspamframesinhtml' = 'on';
'markasspamobjecttagsinhtml' = 'on';
'markasspamembedtagsinhtml' ='on';
'markasspamformtagsinhtml' = 'on';
'markasspamwebbugsinhtml' = 'on';
'markasspamsensitivewordlist' = 'on';
'markasspamspfrecordhardfail' = 'on';
'markasspamfromaddressauthfail' = 'on';
'markasspamndrbackscatter' = 'on';
'phishspamaction' = 'movetojmf';
'spamaction' = 'movetojmf';
'zapenabled' = $true
}

new-hostedcontentfilterpolicy @policyparams

The first basically sets up an array of all the parameters you are going to see into the spam policy. It makes it easier to adjust if you need to.

The second command creates a new policy based off this array that will be called ‘Configured Policy’.

However, after running these two commands you aren’t quite done yet because you have created the policy BUT you actually need to create a rule that uses this policy to do that use the following:

$ruleparams = @{
'name' = 'Configured Recipients';
'hostedcontentfilterpolicy' = 'Configured Policy';
## this needs to match the above policy name
'recipientdomainis' = 'domain.com';
## this needs to match the domains you wish to protect in your tenant
'Enabled' = $true
}

New-hostedcontentfilterrule @ruleparams

You’ll need to ensure the policy names match as noted and you include the domains you wish to protect.

image

Once this has been completed, if you go and look in your Exchange Admin area, under protection and spam filter, you should see a new policy called ‘Configured Recipients’ that was created by the above script commands.

Save the script away and run it as many times as you need. That should make life easier!