Remove-MgUserMessage is a Microsoft Graph PowerShell cmdlet used to permanently delete email messages from a user’s mailbox. The message is identified using its unique MessageId and is removed from the specified user’s Outlook mailbox.
This cmdlet directly interacts with Microsoft Graph and bypasses client-side Outlook rules.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Administrators use Remove-MgUserMessage to:
It is especially useful in security response and mailbox automation scenarios.
Before using this cmdlet, ensure:
Connect-MgGraph -Scopes "Mail.ReadWrite"
Basic syntax:
Remove-MgUserMessage -UserId <String> -MessageId <String>
Remove-MgUserMessage -UserId "user@domain.com" -MessageId "AAMkADhZD3KZAAA="
Deletes the specified email message from the user’s mailbox.
$messages = @("AAMkADhZD3KZAAA=", "AAMkADhZD3KZAAQ=")
foreach ($messageId in $messages) {
Remove-MgUserMessage -UserId "user@domain.com" -MessageId $messageId
}
Note:
Use the Get-MgUserMessage cmdlet to retrieve message IDs.
$folderMessages = Get-MgUserMessage -UserId "user@domain.com" `-MailFolderId "AQMkADhZD3KZAAAA=" -All
foreach ($message in $folderMessages) {
Remove-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id
}
Note:
Use Get-MgUserMailFolder to retrieve the MailFolderId.
$oldMessages = Get-MgUserMessage -UserId "user@domain.com" ` -Filter "receivedDateTime lt 2023-01-01"
foreach ($message in $oldMessages) {
Remove-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id
}
Deletes messages received before a specific date.
| Key Point | Details |
| Cmdlet Name | Remove-MgUserMessage |
| Purpose | Permanently deletes emails from a mailbox |
| Required Scope | Mail.ReadWrite |
| Target | User mailbox messages |
| Primary Parameters | UserId, MessageId |
| Automation Benefit | Enables bulk and conditional email deletion |
| Common Use Case | Phishing cleanup, mailbox hygiene, compliance actions |
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex