microsoft-365-docs
microsoft-365-docs copied to clipboard
Need PowerShell info for anti-spam settings
We really could use some information on the powershell equivalents to get and set anti-spam settings on this page. For example, how to export and import blocked domains.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 52e7d6c9-1a05-440e-730b-ed1dff89c7e4
- Version Independent ID: 4ebfc3af-bad1-bc19-1977-a529eeb5d0c6
- Content: Anti-spam protection - Office 365
- Content Source: microsoft-365/security/office-365-security/anti-spam-protection.md
- Product: m365-security
- Technology: mdo
- GitHub Login: @chrisda
- Microsoft Alias: chrisda
@jhuettner, I would contend that much of that is already covered in the companion procedural topic to this conceptual topic: Configure anti-spam policies in EOP.
Granted, the specific example of importing/exporting blocked domains is not present in that topic.
We could also add such examples in the anti-spam policy cmdlet reference topics: Get-HostedContentFilterPolicy and Set-HostedContentFilterPolicy.
Comments?
Chris,
Thank you for responding! My specific goal was to backup our anti-spam filter policies, particularly permitted email addresses and domains and blocked email addresses and domains. As you know, there is no way to do that through the web GUI. Also, the way the web GUI is implemented, you cannot highlight all the records and cut/paste to notepad/CSV either. So I figured PowerShell was my only resort.
Googling for solutions, I tried both the page you referenced (Configure anti-spam policies in EOP). That page explains using Get-HostedContentFilterPolicy and Get-HostedContentFilterRules at a high-level but don't detail how to get this information. In my opinion, it also doesn't really make clear which cmdlet maps to which section.
As you indicated, the cmdlet references don't include that either. My recommendation would be to include a summary at the Configure page and detailed examples in the HostedContentFilterPolicy page. There is no GUI equivalent meaning anyone trying to do this is going to need help. I ended up abandoning my attempt because it was simply too complex, and Get-HostedContentFilterPolicy gives no easy indication how to get there.
@jhuettner, does this work?
$x = Get-HostedContentFilterPolicy
$x | foreach {write-host ("`r`n"*3)$_.Name,`r`n,("="*79),`r`n,"Allowed Senders"`r`n,("-"*79),`r`n,$_.AllowedSenders,("`r`n"*2),"Allowed Sender Domains",`r`n,("-"*79),`r`n,$_.AllowedSenderDomains,("`r`n"*2),"Blocked Senders"`r`n,("-"*79),`r`n,$_.BlockedSenders,("`r`n"*2),"Blocked Sender Domains",`r`n,("-"*79),`r`n,$_.BlockedSenderDomains}
@chrisda, it does work, it allows me to at least get a text version of the data. Thank you for the help! I would suggest maybe an example that would dump to CSV or JSON and then another example of importing. For the Get-HostedContentFilterPolicy.BlockedSenderDomains Property, each object appears to be of a multi-value type. One of the type properties is "MatchSubDomains". It would be great to document if this actually works since it's not available in the GUI and has been something tons of people have been asking for.
@jhuettner, I'm going with what I have as far as the example.
Regarding the MatchSubDomains property, if there isn't a corresponding parameter in the New- or Set- cmdlet, then there's nothing to configure. We typically don't document the output of Get- cmdlets for just that reason: there are often unimportant properties and values shown (for example, on-premises only settings shown in cloud objects).
Thanks for the feedback
Closing