?
Solved

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

Posted on 2012-04-05
7
Medium Priority
?
3,891 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
  • 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
If you have come across a situation where you need to find some EDB mailbox recovery techniques, then here you will find the same. In this article, we will take you through three techniques using which you will be able to perform EDB recovery. You …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
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

850 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