I am looking for help with Microsoft Exchange PowerShell. I have customer requesting we delete all emails older then 2 years in just 1 folder for just 1 user.

6 Spice ups

Welcome.

We’re happy to help, but not a script writing service. What have you tried? Where are you stuck?

Is this in o365 or an on prem Exchange?

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

2 Spice ups

This should delete the content (from Exchange Management PS) :

Search-Mailbox -Identity "USERNAME" -SearchQuery '(Received:01/01/2000..01/29/2017)' -TargetFolder "Folder" -deletecontent -force

Try something like this (from Exchange Management PS) to give yourself permission to work on the mailbox if you don’t have it. The folder part is the tricky one unless it’s the trash bin. I’ve heard of people getting it to work, but I’m not one of those people. Advice worth what you paid for it. Failing that, log into the machine or OWA and do it with the GUI.

Get-Mailbox -Identity "USERNAME"| add-mailboxpermission -user administrator -AccessRights FullAccess

But it’s kind of heavy handed. If the user has some important stuff saved you’ll obliterate it unless it’s archived in a PST.

Sorry if it’s not perfect, I didn’t test it, but it should give you an idea of where to start.

Is this going to be an ongoing thing? If so why not just set up a retention tag of 1 year and assign it to that folder in their mailbox. That way it automatically deletes.

if it’s just for one user, get hold of his mailbox and delete it from your Outlook.

Thank you for all the help. I followed badbanan’s idea and just deleted the emails from Outlook. It was the quickest resolution. I am going to keep the other suggestions and try them out when I have some spare time.