Hello,
Exchange ServerYou may need to delete emails from more than one mail account before a certain date. For this process, -DeleteContent
parameter can be implemented.
Below I am sharing a PowerShell script to delete emails received before a specified date. This script imports user information from a CSV file and deletes emails received before the specified date for each user.
Previously on Exchange Server Search-Mailbox, New-ComplianceSearch ve -DeleteContent We mentioned its parameters, you can access the relevant article below.
Exchange Server Bulk Delete Content Script
With the script I created below, you can delete mail items before the date you specified in the "Received" section in MBxs in the CSV file you imported.
cengizyilmaz1/Import-DeleteContent (github.com)
#Cengiz YILMAZ
#Microsoft MVP
#www.cengizyilmaz.net
#23.01.2023
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$importFile = "C:Kitap1.csv"
$users = Import-Csv -Path $importFile | Select-Object -ExpandProperty EmailAddress
foreach ($user in $users) {
$search = Search-Mailbox -Identity $user -SearchQuery "Received<8/1/2022" -DeleteContent -Force
}
This script deletes emails from users' mailboxes that were received before August 1, 2022. Before performing this operation, it is important to have a backup of the data to be deleted. The deletion process cannot be undone and the loss of data may be permanent.