none
Get-Date is returning the wrong results RRS feed

  • Question

  • Hi.  This should be simple, but it ain't. :-/

    I'm trying to find all get-mailboxsearch results where the attribute "LastStartTime" is equal to or greater than 90 days previous from today's date.  That is, ignore any get-mailboxsearch results that were started within the last 90 days based on the mailbox searches LastStartTime value.  Anything after that 90 days, i want to see it.

    So here's what i ran

    Get-MailboxSearch -ResultSize unlimited | where {($_.LastStartTime -gt (Get-Date).AddDays(-91))} |Select Name,LastStartTime |more

    ..And here's the first few results it returned..

    LastStartTime
    ----
    12/27/2019 17:17:09
    12/27/2019 17:15:27
    12/27/2019 17:13:20
    12/27/2019 17:12:01
    12/16/2019 16:53:00
    12/16/2019 16:51:40
    12/16/2019 16:51:00
    12/16/2019 14:53:14
    12/13/2019 16:10:51
    12/13/2019 16:08:27

    Today is January 27th, so for whatever reason it's returning results that are 30 days or older, not 91 as i had specified.

    What am i doing wrong?

    ..And thanks! :)

    Monday, January 27, 2020 3:23 PM

All replies

  • You are asking for the gt which brings the recent ones. Try lt instead.

    This posting is provided AS IS with no warranties or guarantees , and confers no rights.

    Ahmed MALEK

    My Website Link

    My Linkedin Profile

    My MVP Profile

    Monday, January 27, 2020 3:33 PM
  • Hi Ahmed.  With gt it returns this..

     

    LastStartTime
    ----

    01/20/2020 17:16:01
    01/20/2020 17:13:49
    01/20/2020 17:10:58
    01/20/2020 17:08:34
    01/14/2020 15:23:38
    01/08/2020 15:00:29
    01/06/2020 17:12:12
    01/06/2020 17:10:56
    01/06/2020 17:07:51
    01/06/2020 17:06:18
    01/02/2020 21:19:49
    01/02/2020 21:17:03
    10/22/2019 20:26:20
    10/22/2019 20:23:09
    10/22/2019 20:21:42
    10/22/2019 20:20:03

    Doesn't make any sense. :-(

    Monday, January 27, 2020 3:40 PM
  • Based on my last result i modified my command to exclude any date that had the year 2020 listed.

    Get-MailboxSearch -ResultSize unlimited | where {($_.LastStartTime -lt (Get-Date).AddDays(-91) -and $_.LastStartTime -notmatch "2020")} |Select Name,LastStartTime |more

    Amazingly, that worked.  But that's not a fix.  To me it just means that powershell doesn't know how to handle the year 2020.  Or so it appears.

    Monday, January 27, 2020 3:47 PM
  • Could you show us the values of $_.LastStartTime and (Get-Date).AddDays(-91) ?

    my blog: http://shserg.ru/

    Tuesday, January 28, 2020 7:01 AM
  • I'm not sure what you mean.
    Tuesday, January 28, 2020 6:23 PM