• Status: Open
  • Priority: Low
  • Security: Public
  • Views: 23
  • Last Modified:

Powershell Script to delete all emails before 1/1/17

I would like a powershell script that deletes all emails older than January 1st, 2017 in microsoft exchange
0
Khari Turner
Asked:
Khari Turner
  • 4
  • 3
8 Comments
 
Dorababu MSenior Software EngineerCommented:
Try this by changing the filter as per your requirement

Get-Mailbox -Identity “USERHERE” | Search-Mailbox -ContentFilter {Size -gt 1024KB} -and {((Received -lt ’12/06/2010) -and (Received -ge ’01/01/2013')) -DeleteContent -force

Search-Mailbox -Identity <username> -SearchQuery '(Received:09/20/2012..10/12/2012)' -deletecontent

Open in new window

0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
What version of exchange are you?
Jose
0
 
Khari TurnerAuthor Commented:
My version is 14.3.361.4001, so i think 2010
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Yes to be exact: Update Rollup 18 for Exchange Server 2010 SP3
Source: https://technet.microsoft.com/en-us/library/hh135098%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396

Do you need to delete the emails in all mailboxes? or just in one specific one?.

jose
0
 
Khari TurnerAuthor Commented:
Yes I need to delete ALL of the mailboxes of all files that predate 1/1/2017. I just tried:
Get-Mailbox -Identity “User” | Search-Mailbox -identity "User" -SearchQuery 'Received<01/24/2018' -DeleteContent -force

Just to Test and see if I could delete some emails from my mail box that predate January 24th but I get the error:

Get-Mailbox : The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Yes, that's why I asked the version of exchange.
That command should work, are you using the powershell command for exchange?
Source:https://technet.microsoft.com/en-us/library/bb123685(v=exchg.141).aspx
jose
0
 
Khari TurnerAuthor Commented:
Yes I am, I'm trying to use it for Microsoft Outlook
0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
I mean you need to run the script on the Exchange Console for 2010.
https://technet.microsoft.com/en-us/library/bb123778(v=exchg.141)
1

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now