Solved

Remove Deleted Items within Date Range via Exchange Management Shell

Posted on 2015-01-12
3
380 Views
Last Modified: 2015-01-30
We are looking for an Exchange management shell command that will specify a user's mailbox and delete messages from their deleted items folder within a specified date range.

Any assistance would be appreciated.,
0
Comment
Question by:GR JN
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40544474
You can try the following powershell script to accomplish this...

This command below will do one individual user.
$Date = get-date
New-MailboxExportRequest -ContentFilter {(Received -lt $date.adddays(-100)) -and (Received -gt $date.adddays(-150) )} -Mailbox <mailboxName> -IncludeFolders "#DeletedItems#" -FilePath "\\servername\PSTFILES\name.pst"

Open in new window


If you want to do this for multiple users at once use the below command...
$Users = get-content "c:\users.txt"
$Date = get-date
foreach ($user in $Users) {
New-MailboxExportRequest -ContentFilter {(Received -lt $date.adddays(-100)) -and (Received -gt $date.adddays(-150) )} -Mailbox $User -IncludeFolders "#DeletedItems#" -FilePath "\\servername\PSTFILES\$User.pst"
}

Open in new window


Will.
0
 

Author Comment

by:GR JN
ID: 40544487
Thanks is there any way to do this from the exchange management shell directly without the need for .pst files?

If possible we would like to use something like the below but specify the deleted items folder and a date range:

Search-Mailbox -Identity "April Stewart" -SearchQuery "Subject:'Your bank statement'" -DeleteContent
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 total points
ID: 40544798
When you are using Search-Mailbox and you want to deleted content you still need to provide a -Targetmailbox where the items can be copied to before you actually remove them from the mailbox.

Unfortunately you cannot use Search-mailbox cmdlet to accomplish subfolder deletions. You have to search the entire folder using the Search-Mailbox cmdlet.

See the link below for additional details
Cannot Search/Delete sub folder items using Search-Mailbox

Will.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question