?
Solved

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

Posted on 2012-04-05
7
Medium Priority
?
3,832 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
New style of hardware planning for Microsoft Exchange server.
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…
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…
Suggested Courses

801 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