Solved

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

Posted on 2012-04-05
7
3,601 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

 
LVL 1

Author Comment

by:FSYR
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

Join & Write a Comment

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
In this video we show how to create an Address List 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 Organization >> Ad…

744 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

15 Experts available now in Live!

Get 1:1 Help Now