0

According to my powershell code shown, it should delete all items between 90 days ago and yesterday. For example if I ran this now the date range would be 1/29/2014 - 4/28/2014.

$x = ((get-date).addDays(-90)).ToShortDateString()
$y = ((get-date).addDays(-1)).ToShortDateString()
$xy = "$($x)..$($y)"

Search-Mailbox bunnyb2 -SearchQuery "Received:$xy" -DeleteContent -Force

This is deleting most of the mail it is supposed to. However the mailbox still retains all deleted email up until ((get-date).addDays(-1)) at 7pm. The last 5 hours of email that should be deleted are not.

At first I thought it could be a time conversion issue however the machine I am running the command on is in Central Time USA, and the mailbox server is also Central Time USA.


Also, please do not tell me to do "Search-Mailbox whismj-SearchQuery "Received:<$y" -DeleteContent -Force". This is a whole other can of worms for me. While the code execute absolutely nothing is returned or deleted. However when I take off the < all email that was received yesterday is deleted.

Johnrad
  • 2,637
  • 18
  • 58
  • 98
  • "According to my powershell code shown" .... ? – Cole9350 Apr 29 '14 at 19:08
  • Isn't Central time UTC-5 right now due to daylight savings time? All time queries should be done in UTC, not local time. Doesn't matter if your server is in the same time zone, or across the world from you. – TheMadTechnician Apr 29 '14 at 19:26
  • @Cole9350 sorry about that man. I accidentally removed it somehow. – Johnrad Apr 29 '14 at 19:37
  • @TheMadTechnician I am deleting content based on a range of mm/dd/yyyy dates only. Not specifying a specific time. – Johnrad Apr 29 '14 at 19:38
  • Doesn't matter. A day, any given day, starts at 12:00:00AM and ends at 11:59:59PM. The inclusion of those times is implied if not stated. The Day ends 5 hours earlier in the UTC time zone than your local time zone, that is why the deletion is leaving things after 7:00PM. – TheMadTechnician Apr 29 '14 at 19:41
  • Please don't get me wrong, I understand you are not including a time in your search parameters. That doesn't mean that the provider performing that search does not use a time when executing it. I am not sure how to modify your command to fix it. – TheMadTechnician Apr 29 '14 at 19:45
  • Well - Whenever I try and specify a time to the seconds, it doesn't accept my input. Thanks for your help recently. – Johnrad Apr 29 '14 at 19:48

1 Answers1

0

I realize this is an older post, but maybe this will help someone searching.

In order to hit the whole date range, you need to provide multiple options to the -SearchQuery parameter (which is expecting a full AQS query). I've never had luck using the syntax you're using, even though it's listed in the documentation; adding the explicit time seems work when using two Received blocks instead of trying to combine them.

To get all mail in January 2015, try using the following:

-SearchQuery "Received: > $('01/01/2015 00:00:00') AND Received: < $('01/31/2015 23:59:59')