Commands › Exchange Online

New-SweepRule

Exchange Online ExchangeOnlineManagement New-*

Create Sweep rules in mailboxes. Sweep rules run at regular intervals to help keep your Inbox clean.

Quick start script

# New-SweepRule — 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-SweepRule
$before | Format-List

# 3. Make the change (dry run first)
New-SweepRule -Name <String> -Provider <String> -WhatIf
New-SweepRule -Name <String> -Provider <String>

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

Syntax

New-SweepRule [-Name] <String> -Provider <String>
 [-Confirm]
 [-DestinationFolder <MailboxFolderIdParameter>]
 [-DomainController <Fqdn>]
 [-Enabled <Boolean>]
 [-ExceptIfFlagged <Boolean>]
 [-ExceptIfPinned <Boolean>]
 [-KeepForDays <Int32>]
 [-KeepLatest <Int32>]
 [-Mailbox <MailboxIdParameter>]
 [-Sender <RecipientIdParameter>]
 [-SourceFolder <MailboxFolderIdParameter>]
 [-SystemCategory <SystemCategoryType>]
 [-WhatIf]
 [<CommonParameters>]

Parameters (15)

ParameterTypeRequiredWhat it controls
-Name String yes The Name parameter specifies the name of the Sweep rule. If the value contains spaces, enclose the value in quotation marks.
-Provider String yes The Provider parameter specifies the provider for the Sweep rule. If the value contains spaces, enclose the value in quotation marks.
-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.
-DestinationFolder MailboxFolderIdParameter The DestinationFolder parameter specifies an action for the Sweep rule that moves messages to the specified folder. The syntax is `MailboxID:\ParentFolder[\SubFolder]`.
-DomainController Fqdn This parameter is available only in on-premises Exchange.
-Enabled Boolean The Enabled parameter specifies whether the Sweep rule is enabled or disabled. Valid values are:
-ExceptIfFlagged Boolean This parameter is available only in on-premises Exchange.
-ExceptIfPinned Boolean This parameter is available only in on-premises Exchange.
-KeepForDays Int32 The KeepForDays parameter specifies an action for the Sweep rule that specifies the number of days to keep messages that match the conditions of the rule. After the number of days have passed, the messages are moved...
-KeepLatest Int32 The KeepLatest parameter specifies an action for the Sweep rule that specifies the number of messages to keep that match the conditions of the rule. After the number of messages is exceeded, the oldest messages are...
-Mailbox MailboxIdParameter The Mailbox parameter specifies the mailbox where you want to create the Sweep rule. You can use any value that uniquely identifies the mailbox. For example:
-Sender RecipientIdParameter The Sender parameter specifies a condition for the Sweep rule that looks for the specified sender in messages. For internal senders, you can use any value that uniquely identifies the sender. For example:
-SourceFolder MailboxFolderIdParameter The SourceFolder parameter specifies a condition for the Sweep rule that looks for messages in the specified folder. The syntax is `MailboxID:\ParentFolder[\SubFolder]`.
-SystemCategory SystemCategoryType The SystemCategory parameter specifies a condition for the sweep rule that looks for messages with the specified system category. System categories are available to all mailboxes in the organization. Valid values are:
-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.