[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Exchange 2010 export and delete scripts

Hi

I would like to export mail items from Exchange to pst format and then delete whatever I have exported excluding the calendar and task items.

I ran the following Script to export items:

New-MailboxExportRequest -Mailbox UserA -FilePath "\\SERVER\Share\UserA.pst"
 -ContentFilter {(Received -lt "12/31/2011")}

The export seem to have succeeded properly but when I run the following Delete command I get a date and time error:

I have tried various date formats of the following script
Search-Mailbox -Identity userA -SearchQuery 'received:<31/12/2011' -DeleteContent

I have slo tried:
Search-Mailbox -Identity userA -SearchQuery 'received:<31/12/2011 00:00:00' -DeleteContent


All of these Delete sctipts gave me a date and time format error (even though my server date is setup for dd/MM/yyyy as short date format)

I did however manage to delet ALL content from userA mailbox by means of changing the date as follow:

Search-Mailbox -Identity UserA -SearchQuery 'received:<2011/12/31' -DeleteContent

Please can someone assist be rectifying the Delete script so that only items older than 31/12/2011 gets deleted and calendar and taks are exluded from deletion.

Thank you
0
QGSmith
Asked:
QGSmith
  • 3
  • 2
1 Solution
 
AkhaterCommented:
Try


Search-Mailbox -Identity User -SearchQuery "Received:<$('12/21/2011')" -DeleteContent
0
 
QGSmithAuthor Commented:
Do you know if/how to exclude calendar and tasks in the script too?
0
 
AkhaterCommented:
From a previous answer of mine http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_27438932.html

Search-Mailbox -identity "mailboxname" -SearchQuery "kind:email AND Sent:> $('2006-12-31') AND Sent:< $('2008-01-01')"  -Confirm:$false -Force -TargetMailbox "targetuser" -TargetFolder "SearchAndDeleteLog" -LogLevel Full -DeleteContent

Open in new window

0
 
QGSmithAuthor Commented:
Thank you for this. I will test and let you know if it works
0
 
QGSmithAuthor Commented:
Thank you Akhater

Your Script worked by minipulating it this way:

Search-Mailbox -identity UserA -SearchQuery "kind:email AND Sent:> $('2010-
01-01') AND Sent:< $('2011-12-31')" -DeleteContent


Thanks again
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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