Commands › Exchange Online

New-EOPProtectionPolicyRule

Exchange Online ExchangeOnlineManagement New-*

Create rules for the built-in security features for all cloud mailboxes in preset security policies. The rules specify recipient conditions and exceptions for the protection, and also allow you to turn on and turn off the associated preset security policies. **Note**: Unless you manually removed a rule using the Remove-EOPProtectionPolicyRule cmdlet, we don't recommend using this cmdlet to create rules. To create the rule, you need to specify the existing individual security policies that are associated with the preset security policy. We never recommend creating these required individual secu

Quick start script

# New-EOPProtectionPolicyRule — quick start (serv365.ai)
# 1. Connect (app-only shown; interactive: omit the certificate parameters)
Connect-ExchangeOnline -CertificateThumbprint $thumb -AppId $appId -Organization $org

# 2. Capture the current state first — you cannot roll back what you never recorded
$before = Get-EOPProtectionPolicyRule
$before | Format-List

# 3. Make the change (dry run first)
New-EOPProtectionPolicyRule -Name <String> -AntiPhishPolicy <AntiPhishPolicyIdParameter> -HostedContentFilterPolicy <HostedContentFilterPolicyIdParameter> -WhatIf
New-EOPProtectionPolicyRule -Name <String> -AntiPhishPolicy <AntiPhishPolicyIdParameter> -HostedContentFilterPolicy <HostedContentFilterPolicyIdParameter>

# 4. Verify and diff
$after = Get-EOPProtectionPolicyRule
Compare-Object ($before | Out-String) ($after | Out-String)

Syntax

New-EOPProtectionPolicyRule [-Name] <String> [-Priority <Int32>] -AntiPhishPolicy <AntiPhishPolicyIdParameter> -HostedContentFilterPolicy <HostedContentFilterPolicyIdParameter> -MalwareFilterPolicy <MalwareFilterPolicyIdParameter>
 [-Comments <String>]
 [-Confirm]
 [-Enabled <Boolean>]
 [-ExceptIfRecipientDomainIs <Word[]>]
 [-ExceptIfSentTo <RecipientIdParameter[]>]
 [-ExceptIfSentToMemberOf <RecipientIdParameter[]>]
 [-RecipientDomainIs <Word[]>]
 [-SentTo <RecipientIdParameter[]>]
 [-SentToMemberOf <RecipientIdParameter[]>]
 [-WhatIf]
 [<CommonParameters>]

Parameters (15)

ParameterTypeRequiredWhat it controls
-Name String yes The Name parameter specifies a unique name for the rule. The maximum length is 64 characters.
-AntiPhishPolicy AntiPhishPolicyIdParameter yes The AntiPhishPolicy parameter specifies the existing anti-phishing policy that's associated with the preset security policy.
-HostedContentFilterPolicy HostedContentFilterPolicyIdParameter yes The HostedContentFilterPolicy parameter specifies the existing anti-spam policy that's associated with the preset security policy.
-MalwareFilterPolicy MalwareFilterPolicyIdParameter yes The HostedContentFilterPolicy parameter specifies the existing anti-malware policy that's associated with the preset security policy.
-Comments String The Comments parameter specifies informative comments for the rule, such as what the rule is used for or how it has changed over time. The length of the comment can't exceed 1024 characters.
-Confirm SwitchParameter The Confirm switch specifies whether to show or hide the confirmation prompt. How this switch affects the cmdlet depends on whether the cmdlet requires confirmation before proceeding.
-Enabled Boolean The Enabled parameter specifies whether the rule is enabled. Valid values are:
-ExceptIfRecipientDomainIs Word[] The ExceptIfRecipientDomainIs parameter specifies an exception that looks for recipients with email addresses in the specified domains. You can specify multiple domains separated by commas.
-ExceptIfSentTo RecipientIdParameter[] The ExceptIfSentTo parameter specifies an exception that looks for recipients in messages. You can use any value that uniquely identifies the recipient. For example:
-ExceptIfSentToMemberOf RecipientIdParameter[] The ExceptIfSentToMemberOf parameter specifies an exception that looks for messages sent to members of groups. You can use any value that uniquely identifies the group. For example:
-Priority Int32 The Priority parameter specifies a priority value for the rule that determines the order of rule processing. A lower integer value indicates a higher priority, the value 0 is the highest priority, and rules can't...
-RecipientDomainIs Word[] The RecipientDomainIs parameter specifies a condition that looks for recipients with email addresses in the specified domains. You can specify multiple domains separated by commas.
-SentTo RecipientIdParameter[] The SentTo parameter specifies a condition that looks for recipients in messages. You can use any value that uniquely identifies the recipient. For example:
-SentToMemberOf RecipientIdParameter[] The SentToMemberOf parameter specifies a condition that looks for messages sent to members of distribution groups, dynamic distribution groups, or mail-enabled security groups. You can use any value that uniquely...
-WhatIf SwitchParameter The WhatIf switch shows what the command does without making any changes. You don't need to specify a value with this switch.

Reference facts derived from Microsoft documentation, © Microsoft, licensed CC BY 4.0; restructured with original guidance by serv365.ai.