Solved

Exchange 2010 - Powershell

Posted on 2013-10-23
6
611 Views
Last Modified: 2013-10-23
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
Comment
Question by:ym1
  • 4
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39594585
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
 

Author Comment

by:ym1
ID: 39594631
Subsun thanks it's doing part of the job as not delete the contacts but it not clear tasks and calendar.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
ID: 39594750
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 40

Expert Comment

by:Subsun
ID: 39595089
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
 

Author Comment

by:ym1
ID: 39595285
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39595300
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

776 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