Solved

Remove Deleted Items within Date Range via Exchange Management Shell

Posted on 2015-01-12
3
360 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we show how to create an email address policy 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 Mail Flow…
This video discusses moving either the default database or any database to a new volume.

861 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

22 Experts available now in Live!

Get 1:1 Help Now