[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How can I delete emails after a certain date, without retention policies.

Posted on 2012-04-05
7
Medium Priority
?
3,871 Views
Last Modified: 2015-05-17
I'm trying to delete emails before certain date (10/01/2011) from one mailbox.  I don't want to adjust any retention policies.  

It looks like in Exchange 2007 there was a simple powershell command (Export-Mailbox) to do this, which doesn't exist in 2010.  Exchange 2010 has Search-Mailbox (doesn't do dates), and New-MailboxExportRequest.  

New-MailboxExportRequest looks like it would do it, but it is unrecognized in Exchange Powershell.
0
Comment
Question by:FSYR
[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
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:tobyweston
ID: 37812176
They changed the Export-Mailbox to New-MailboxExportRequest in 2010 SP1. This command will help you export the emails to a file if you need to back them up before removing them.

It wont remove the files like the -deletecontent switch did with Export-Mailbox. YOu will need to use the Search-Mailbox cmdlet with the -deletecontent switch to do that.

Search-Mailbox -Identity <mailboxname> -SearchQuery 'Received:>$("01/04/2012") and Received:<$("01/05/2012")` -deletecontent

Open in new window



A side note - you will need to make sure the user that you are trying to perform the New-MailboxExportRequest has the Import Export permission. Otherwise the command may not show as a recognised command.

This can be done with the New-ManagementRoleAssignment cmdlet.

i.e.
New-ManagementRoleAssignment –Role "Mailbox Import Export" –User Administrator

Open in new window

0
 
LVL 1

Author Comment

by:FSYR
ID: 37812460
I ran the example script and it shows The term 'New-MailboxExportRequest' is not recognized as the name of a cmdlet, function, script fileor operable program.
0
 
LVL 3

Expert Comment

by:tobyweston
ID: 37812871
Did you do the permissions before running that cmdlet? You will see that error if the user running the cmdlet doesnt have permission to do Import Export.

If you have then try this:

Launch Exchange Management Shell
Run “Add-pssnapin microsoft*”
Run “Install-CannedRbacRoles”
Run “Install-CannedRbacRoleAssignments”
Close and re-open Exchange Management Shell

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:FSYR
ID: 37813154
Thanks,

Well, since I don't have a need to backup the messages, I'm using the Search-Mailbox command that you listed.

It comes up with "Please adjust the date time.  Make sure it is the correct format."
+CategoryInfo : InvalidArgument:  (:) [ ], ParserException
0
 
LVL 3

Accepted Solution

by:
tobyweston earned 2000 total points
ID: 37813227
Cant test it at the moment, but it may be my typo.

Search-Mailbox -Identity <mailboxname> -SearchQuery 'Received:>$("01/04/2012") and Received:<$("01/05/2012")' -deletecontent

Open in new window


Wrong type of apostrophe after the last date.

If you are deleting everything from a certain date like you mentioned then this should be sufficient:

Search-Mailbox -Identity <mailboxname> -SearchQuery "Received:<$('01/04/2012')" -deletecontent

Open in new window


Be aware the search query is based on locality. So date will be in the computers date format and "Received" will be spelt in the language the locale is if different from English.
0
 
LVL 1

Author Comment

by:FSYR
ID: 37813301
I found the issue.  The single (or double) quotes weren't needed.  Worked like a charm!!  Thanks for the direct syntax.

Ran:
Search-Mailbox -Identity mailboxname -SearchQuery Received:<$("10/01/2010") -deletecontent
0
 

Expert Comment

by:metronetworksllc
ID: 40782014
Is there away to run this command, on the entire datastore?  

We implemented an archiving solution and we are trying to delete all emails past a certain date.  The above command would work if we could adjust it to run on the entire database instead of the mailbox.
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
In this video we show how to create an Accepted Domain 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 >> Ac…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

656 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