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
Solved

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

Posted on 2012-04-05
7
3,693 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 500 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

829 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