Commands › Exchange Online

Set-SweepRule

Exchange Online ExchangeOnlineManagement Set-*

Modify Sweep rules in mailboxes.

Quick start script

# Set-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)
Set-SweepRule -Identity <SweepRuleIdParameter> -WhatIf
Set-SweepRule -Identity <SweepRuleIdParameter>

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

Syntax

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

Parameters (16)

ParameterTypeRequiredWhat it controls
-Identity SweepRuleIdParameter yes The Identity parameter specifies the Sweep rule that you want to modify. You can use any value that uniquely identifies the rule. For example:
-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 This parameter is reserved for internal Microsoft use.
-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 that contains the rule you want to modify. You can use any value that uniquely identifies the mailbox. For example:
-Name String The Name parameter specifies the name of the Sweep rule. If the value contains spaces, enclose the value in quotation marks.
-Provider String The Provider parameter specifies the provider for the Sweep rule. If the value contains spaces, enclose the value in quotation marks.
-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.