Solved

Remove Deleted Items within Date Range via Exchange Management Shell

Posted on 2015-01-12
3
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
To show how to create a transport rule 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 >> Rules tab.:  To cr…
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…

717 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