Link to home
Start Free TrialLog in
Avatar of CodeBlueEngineers
CodeBlueEngineers

asked on

Exchange 2013, Powershell command to delete email older than a date

Can anyone supply me with a script/command to delete all emails, calendars, contacts and everything else in all users mailboxes older than a certain date. This is for all users in an exchange 2013 environment.
The reason for this is we recently imported all email from another system/domain as part of a project and all email has appeared as unread (including calendars). This is a great inconvenience to the site.
The method for migrating the email is to export to pst from the old system and import in the new using powershell, the initial export is where we found the issue occurred with setting all email to unread.
We have now figured out how to export the email correctly without appearing as unread and saving the state from the previous system, but if we try a new-mailboximportrequest with the pst now it detects the email is already in there and doesn't copy over the top. And if we try a manual import of the pst through outlook setting "replace duplicates with items imported" it just goes and creates a whole bunch of duplicates.

Once we have the command to delete the email older than a certain date we will run the import again with the pst files that now have the correct state applied.

However if anyone can supply me with an alternative to the above, eg software which can import the pst over the top and correct the state that would be even better.
SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodeBlueEngineers
CodeBlueEngineers

ASKER

Brilliant, thanks for that, also can you provide the command for deleting from a single user, just so I can test it out
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic, and will that also delete contacts, calendars and tasks etc
This will be mailbox items. I have only tested this in my lab so i do not know about the contacts/calendars. You will just have to test it.

Will.
Hi Will
After running the command I get another cursor line example

get-mailbox -resultsize "unlimited" | search-mailbox -SearchQuery "Received:<$(11/01/2013')" -deletecontent

then push enter and I get this
>>
Not quite sure what to put there
Sorry, there should be a single quote ' before the 11 in the date. That should do it.

Will.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry at the bottom I meant to say the command for 1 user and the command for all users
I've requested that this question be closed as follows:

Accepted answer: 0 points for CodeBlueEngineers's comment #a39660558

for the following reason:

The above commands are what helped us workaround the issue
If this solution help get to the end result the points should be awarded fairly.

Will.
This is what fixed the issue