Solved

Remove Deleted Items within Date Range via Exchange Management Shell

Posted on 2015-01-12
3
349 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now