Delete Exchange Mailbox Emails by Date Range Using PowerShell
Question details
The user needs PowerShell commands to search an on-premises Exchange mailbox, export emails within a specific date range to a network PST file, and subsequently delete them.

- Product
- Microsoft Exchange Server
- Device & OS
- not provided
- Scenario
- Performing administrative mailbox cleanup and archiving for an on-premises Exchange Server using EMS commands.
- Observed behavior
- Seeking the exact PowerShell syntax and steps to securely export and remove older messages based on specific dates.
Ensure you are running the Exchange Management Shell as an administrator and that your account is assigned the 'Mailbox Import Export' management role to run these specific cmdlets.
Use Exchange Management Shell Cmdlets
Utilize built-in Exchange Management Shell (EMS) commands to filter messages by date, export them to a network PST, and then delete the items.
Managing on-premises Exchange mailboxes requires the use of the Exchange Management Shell. The process involves two primary steps: exporting the data using New-MailboxExportRequest and then deleting the content using the Search-Mailbox cmdlet.
Log in to your on-premises Exchange Server and launch the Exchange Management Shell (EMS) as an administrator.
Use the New-MailboxExportRequest cmdlet with the -ContentFilter parameter to isolate the date range and export the data to your network path. Example: New-MailboxExportRequest -Mailbox "UserAlias" -ContentFilter {(Received -lt '01/01/2023')} -FilePath "\\server\share\user.pst"
After confirming the PST export was successful, use the Search-Mailbox cmdlet with the -DeleteContent switch to permanently remove the emails. Example: Search-Mailbox -Identity "UserAlias" -SearchQuery "Received:<01/01/2023" -DeleteContent

Manage Your Daily Documents Easily with WPS Office
While Exchange Server manages your enterprise emails, you can effortlessly handle your daily reports, spreadsheets, and presentations with WPS Office. It provides a lightweight, highly compatible, and free alternative to Microsoft Office.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install the Software: Run the downloaded setup file and follow the simple on-screen instructions to complete the installation.
- 3. Start Creating: Open WPS Office and immediately start creating or editing your documents, spreadsheets, and presentations.

Frequently Asked Questions
Do I need special permissions to export and delete Exchange emails via PowerShell?
Yes, your administrator account must be specifically assigned the 'Mailbox Import Export' management role to run the New-MailboxExportRequest and Search-Mailbox cmdlets.
Can I use Exchange Online PowerShell to manage on-premises mailboxes?
No, you must use the on-premises Exchange Management Shell (EMS) for on-premises servers. Exchange Online PowerShell is exclusively designed for Microsoft 365 cloud environments.
How can I verify the emails before permanently deleting them from the mailbox?
You can use the Search-Mailbox cmdlet with the -LogOnly and -TargetMailbox parameters. This generates a detailed report of the emails that match your specific date range before you execute any deletion commands.




