Commands › Exchange Online

Remove-Message

Exchange Online ExchangeOnlineManagement Remove-*

Delete a message from a queue on a Mailbox server or an Edge Transport server.

Quick start script

# Remove-Message — 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-Message
$before | Format-List

# 3. Make the change (dry run first)
Remove-Message -Identity <MessageIdentity> -Filter <String> -WhatIf
Remove-Message -Identity <MessageIdentity> -Filter <String>

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

Syntax — 2 parameter sets

Filter

Remove-Message -Filter <String> [-Server <ServerIdParameter>]
 [-Confirm]
 [-WhatIf]
 [-WithNDR <Boolean>]
 [<CommonParameters>]

Identity

Remove-Message [-Identity] <MessageIdentity>
 [-Confirm]
 [-WhatIf]
 [-WithNDR <Boolean>]
 [<CommonParameters>]

Parameters (6)

ParameterTypeRequiredWhat it controls
-Identity MessageIdentity yes The Identity parameter specifies the message. Valid input for this parameter uses the syntax Server\\Queue\\MessageInteger or Queue\\MessageInteger or MessageInteger, for example, Mailbox01\\contoso.com\\5 or 10. For...
-Filter String yes The Filter parameter specifies one or more messages by using OPATH filter syntax. The OPATH filter includes a message property name followed by a comparison operator and value (for example, `"FromAddress -like...
-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.
-Server ServerIdParameter The Server parameter specifies the Exchange server where you want to run this command. You can use any value that uniquely identifies the server. For example:
-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.
-WithNDR Boolean The WithNDR parameter specifies whether a non-delivery report (NDR) is returned to the sender of a message. The default value is $true. This parameter can be used with both the Identity parameter and Filter parameter sets.

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