header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Another lastLogonTimeStamp question
Last Post 19 Jul 2010 01:46 PM by Gorillo. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
uSlackrUser is Offline
New Member
New Member
Posts:68
Avatar

--
29 Jun 2010 08:15 AM
    I wrote a query that will find all acounts created more than 30 days ago that have Never logged in or logged in more that 60 days ago. I used Powershell v2 but the Quest AD module.  Here's the query (reformatted for the reader)

    Get-QADuser -searchroot "corp.net/user accounts/users/OurOU" | where

       ($_.whencreated -lt ((get-date).adddays(-30)) ) 
       -and 
             ( 
                ( $_.lastLogonTimestamp -like "Never") 
                -or 
                ($_.lastLogonTimestamp -lt ((get-date).adddays(-60)) 
             )
     }

    When it runs, accounts that have never logged in are listed correctly, account that have been logged in, generate an error:
    "Bad argument to operator "-lt" : Cannot compare "Monday, June 16 2010" because it is not iComparible"
    (The error is pointing to the last line of code above)

    since Monday, June 16 2010 is date-looking, I would expect it to fail in the comparison to Never, but it fails in comparison to another date.

    What gives?  How do I fix this?

    Thanks

    \\Greg
    \\uSlackr
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    29 Jun 2010 09:17 AM
    Try running the comparison straight from the command line... It should work. Here is what I got with my account:

    ___________________________________________________________________________________________________________________________________
    PS H:\RFGExchmig> $cameron = Get-QADUser cove -IncludedProperties lastlogontimestamp

    ___________________________________________________________________________________________________________________________________
    PS H:\RFGExchmig> $cameron.lastlogontimestamp -lt (get-date).adddays(-60)
    False

    ___________________________________________________________________________________________________________________________________
    PS H:\RFGExchmig> $cameron.lastlogontimestamp -gt (get-date).adddays(-60)
    True
    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    29 Jun 2010 10:08 AM
    Agreed, it runs fine against my user, but when I run this

    "$usr.lastlogontimestamp -gt (get-date).adddays(-60) "

    against an account that has never logged in, I get

    "Cannot compare "Never" becaue it is not IComparable"
    \\uSlackr
    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    29 Jun 2010 10:38 AM
    So here's some more information.  If I run this with only the "NEVER" portion of the OR clause, it runs without error and lists all users created more than  30 days ago who have never logged in.

    If I swap out the NEVER test and instead compare against the GETDAYS value, every comparison (whether lastlogontimestamp = never or a real date) generates an 'not IComparable error' 

    \\Greg

    \\uSlackr
    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    29 Jun 2010 10:51 AM

    OK, I think I've found it. It appears access lastlogontimestamp.value allows this to work.

    I found this thread http://www.powergui.org/thread.jspa...geID=23210 that got me started.  If I understand correctly, the lastlogintimestamp value is being interpreted by the Quest snappin and the comparison I want to do requires the uninterpreted data. 

    The code below was successful:


    Get-QADuser -searchroot "corp.net/user accounts/users/OurOU" | where

       ($_.whencreated -lt ((get-date).adddays(-30)) ) 
       -and 
       ( 
          ( $_.lastLogonTimestamp.value -like "Never") 
          -or 
          ($_.lastLogonTimestamp.value -lt ((get-date).adddays(-60)) 
       )
     }

    \\uSlackr
    GorilloUser is Offline
    New Member
    New Member
    Posts:1
    Avatar

    --
    19 Jul 2010 01:46 PM
    Posted By uSlackr on 29 Jun 2010 10:51 AM

    OK, I think I've found it. It appears access lastlogontimestamp.value allows this to work.


    I registered just to say thank you for this. Thank you for this.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer