Avatar of E=mc2
E=mc2
Flag for Canada asked on

Powershell script to add an email in the Office 365 Security and Compliance Block List

I would like to use a script, preferably a PowerShell script to prompt for an email address and then add that email address to the Office 365 Security and Compliance Defaul spam filter policy
Block Sender list.
Is this possible?
Thanks in advance.

PowershellMicrosoft OfficeMicrosoft 365AntiSpamScripting Languages

Avatar of undefined
Last Comment
E=mc2

8/22/2022 - Mon
Jose Gabriel Ortega Castro

It's not possible.
You have two options:

* Fill it up manually on the O365 S&C (security and compliance)
* Or manage the Default Spam Policy for everyone (mailbox by mailbox, but there's a cmdlet that does it all for everyone):

https://docs.microsoft.com/powershell/module/exchange/set-mailboxjunkemailconfiguration?view=exchange-ps

To a Single User:
Set-MailboxJunkEmailConfiguration user@mydomain.com -BlockedSendersAndDomains @{Add=" @baddomain.com"} -TrustedSendersAndDomains @{Add="gooddomain.com","sally@safedomain.com"} 

Open in new window

To the whole company
Get-Mailbox -ResultSize Unlimited | Set-MailboxJunkEmailConfiguration -BlockedSendersAndDomains @{Add="@baddomain.com","user@baddomain2.com} -TrustedSendersAndDomains @{Add="gooddomain.com","sally@safedomain.com"} 

Open in new window



ASKER CERTIFIED SOLUTION
Vasil Michev (MVP)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
E=mc2

ASKER
Thanks Vasil much appreciated.
This seems to work once I add the following before your script.
Connect-MsolService -Credential $Credential
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy