New-HostedContentFilterRule

This cmdlet is available only in the cloud-based service.

Use the New-HostedContentFilterRule cmdlet to create spam filter rules (content filter rules) in your cloud-based organization.

For information about the parameter sets in the Syntax section below, see Exchange cmdlet syntax.

Syntax

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

Description

Important

Different types of recipient conditions use AND logic (the recipient must satisfy all specified conditions). Different types of recipient exceptions use OR logic (the recipient must satisfy any of the specified exceptions). For more information, see Use the Microsoft Defender portal to create anti-spam policies.

You need to be assigned permissions before you can run this cmdlet. Although this topic lists all parameters for the cmdlet, you may not have access to some parameters if they're not included in the permissions assigned to you. To find the permissions required to run any cmdlet or parameter in your organization, see Find the permissions required to run any Exchange cmdlet.

Examples

Example 1

New-HostedContentFilterRule -Name "Contoso Recipients" -HostedContentFilterPolicy "Contoso Spam Filter Policy" -RecipientDomainIs contoso.com

This example creates a new spam filter rule named Contoso Recipients with the following settings: If the recipient is in the domain contoso.com, apply the spam filter policy named Contoso Spam Filter Policy.

Parameters

-Comments

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.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-Confirm

The Confirm switch specifies whether to show or hide the confirmation prompt. How this switch affects the cmdlet depends on if the cmdlet requires confirmation before proceeding.

  • Destructive cmdlets (for example, Remove-* cmdlets) have a built-in pause that forces you to acknowledge the command before proceeding. For these cmdlets, you can skip the confirmation prompt by using this exact syntax: -Confirm:$false.
  • Most other cmdlets (for example, New-* and Set-* cmdlets) don't have a built-in pause. For these cmdlets, specifying the Confirm switch without a value introduces a pause that forces you acknowledge the command before proceeding.
Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-Enabled

The Enabled parameter enables or disables the rule. Valid input for this parameter is $true or $false. The default value is $true.

Type:Boolean
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-ExceptIfRecipientDomainIs

The ExceptIfRecipientDomainIs parameter specifies an exception for the rule that looks for recipients with email addresses in the specified domains. You can specify multiple domains separated by commas.

Type:Word[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-ExceptIfSentTo

The ExceptIfSentTo parameter specifies an exception for the rule that looks for recipients in messages. You can use any value that uniquely identifies the recipient. For example:

  • Name
  • Alias
  • Distinguished name (DN)
  • Canonical DN
  • Email address
  • GUID

You can enter multiple values separated by commas. If the values contain spaces or otherwise require quotation marks, use the following syntax: "Value1","Value2",..."ValueN".

Type:RecipientIdParameter[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-ExceptIfSentToMemberOf

The ExceptIfSentToMemberOf parameter specifies an exception for the rule that looks for messages sent to members of distribution groups, mail-enabled security groups, or sent to Microsoft 365 Groups. You can use any value that uniquely identifies the group. For example:

  • Name
  • Alias
  • Distinguished name (DN)
  • Canonical DN
  • Email address
  • GUID

You can enter multiple values separated by commas. If the values contain spaces or otherwise require quotation marks, use the following syntax: "Value1","Value2",..."ValueN".

If you remove the group after you create the rule, no exception is made for messages that are sent to members of the group.

Type:RecipientIdParameter[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-HostedContentFilterPolicy

The HostedContentFilterPolicy parameter specifies the spam filter policy (content filter policy) that's associated with the rule.

You can use any value that uniquely identifies the policy. For example:

  • Name
  • Distinguished name (DN)
  • GUID

You can't specify the default spam filter policy, and you can't specify a spam filter policy that's already associated with another spam filter rule.

Type:HostedContentFilterPolicyIdParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-Name

The Name parameter specifies a unique name for the spam filter rule. The maximum length is 64 characters. If the value contains spaces, enclose the value in quotation marks (").

Don't use the following characters in the name value: \ % & * + / = ? { } | < > ( ) ; : [ ] , ".

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-Priority

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 have the same priority value.

Valid values and the default value for this parameter depend on the number of existing rules. For example, if there are 8 existing rules:

  • Valid priority values for the existing 8 rules are from 0 through 7.
  • Valid priority values for a 9th new rule are from 0 through 8.
  • The default value for the new 9th rule is 8.

If you modify the priority value of a rule, the position of the rule in the list changes to match the priority value you specify. In other words, if you set the priority value of a rule to the same value as an existing rule, the priority value of the existing rule and all other lower priority rules after it is increased by 1.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-RecipientDomainIs

The RecipientDomainIs parameter specifies a condition for the rule that looks for recipients with email addresses in the specified domains. You can specify multiple domains separated by commas.

Type:Word[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-SentTo

The SentTo parameter specifies a condition for the rule that looks for recipients in messages. You can use any value that uniquely identifies the recipient. For example:

  • Name
  • Alias
  • Distinguished name (DN)
  • Canonical DN
  • Email address
  • GUID

You can enter multiple values separated by commas. If the values contain spaces or otherwise require quotation marks, use the following syntax: "Value1","Value2",..."ValueN".

Type:RecipientIdParameter[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-SentToMemberOf

The SentToMemberOf parameter specifies a condition that looks for messages sent to members of distribution groups, mail-enabled security groups, or sent to Microsoft 365 Groups. You can use any value that uniquely identifies the group. For example:

  • Name
  • Alias
  • Distinguished name (DN)
  • Canonical DN
  • Email address
  • GUID

You can enter multiple values separated by commas. If the values contain spaces or otherwise require quotation marks, use the following syntax: "Value1","Value2",..."ValueN".

If you remove the group after you create the rule, no action is taken on messages that are sent to members of the group.

Type:RecipientIdParameter[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

-WhatIf

The WhatIf switch simulates the actions of the command. You can use this switch to view the changes that would occur without actually applying those changes. You don't need to specify a value with this switch.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Exchange Online, Exchange Online Protection

Inputs

Input types

To see the input types that this cmdlet accepts, see Cmdlet Input and Output Types. If the Input Type field for a cmdlet is blank, the cmdlet doesn't accept input data.

Outputs

Output types

To see the return types, which are also known as output types, that this cmdlet accepts, see Cmdlet Input and Output Types. If the Output Type field is blank, the cmdlet doesn't return data.