Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

Exchange 2010 - Powershell

Hi,

I try to delete from some of my users mailbox mails that are older then the 01/01/2000. I'm using:
Search-Mailbox -Identity "USER" -SearchQuery "Received:< 01/01/2010" -DeleteContent -force

It's working, the problem it delete all contacts that added before 01/01/2010 as well.
How can I still delete the mails older than 01/01/2010 but exclude the contacts folder from been deleted?

How to change the SearchQuery.
0
ym1
Asked:
ym1
  • 4
  • 2
1 Solution
 
SubsunCommented:
I don’t think Search-Mailbox will allow you to exclude or only include specific folders.. You can specify the the kind of items to search. So if you specify email, then it will search only for email items..

Try..
Search-Mailbox -Identity "USER" -SearchQuery "'kind:email' AND 'Received:< 01/01/2010'" -DeleteContent -force

Open in new window

0
 
ym1Author Commented:
Subsun thanks it's doing part of the job as not delete the contacts but it not clear tasks and calendar.
0
 
SubsunCommented:
You can add multipple conditions like

"'kind:email' OR 'kind:meetings' OR 'kind:tasks' AND 'Received:< 01/01/2010'"

Open in new window


Ref : http://msdn.microsoft.com/en-us/library/aa965711(v=vs.85).aspx
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
SubsunCommented:
Just wondering about the reason for B grade!

Please see the EE guidelines on grading..
http://support.experts-exchange.com/customer/portal/articles/481419
0
 
ym1Author Commented:
just small point the syntax was not accepted, need to be:
Search-Mailbox -Identity "USER" -SearchQuery "(kind:email) AND (Received:< 01/01/2010)" -DeleteContent -force
0
 
SubsunCommented:
May be, I didn't tried... I cannot connect to my lab now..  If the quotes were not working you can try without quotes.. it should work as well..
Search-Mailbox -Identity "USER" -SearchQuery "kind:email AND Received:< 01/01/2010" 

Open in new window

0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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