Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag 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.

Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

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
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of E=mc2

ASKER

Thanks Vasil much appreciated.
This seems to work once I add the following before your script.
Connect-MsolService -Credential $Credential