1

I'm trying to get some data from the Active Directory in SQL. I use the code:

SELECT * FROM OpenQuery 
( 
ADSI, 
'SELECT  objectGUID, objectSID, employeeID, lastLogon, mobile, telephoneNumber, mail,  department, givenName, sn, displayname,  sAmAccountName
FROM ''LDAP://DC=mycompany''    
where  objectClass = ''user''
and sAmAccountName = ''testuser'''  
)

My problem is that the value i receive for lastLogon isn't refreshing. It is possible that the other values aren't also refreshing, however i can't say this for sure, because in the other data there is no change, but the lastLogon value should be updated when i lock my computer and log in.

Does anyone have any idee why is this, and how can i solve this?

Thanks!

1 Answer 1

2

The lastLogon attribute reflects the last interactive logon, not the last network-based logon

More info found here

This is some excellent information from this site

Another twist: Active Directory does NOT replicate the LastLogon attribute across domain controllers. So in order to get an accurate value, you need to obtain the LastLogon value for the same user from all your domain controllers and accept the value that is highest.

2
  • if i make a query from a C++ application then it is updated. Why is that?
    – kampi
    Commented Feb 1, 2012 at 13:37
  • @kampi: IIRC, An ADSI linked server hits the same DC, not the domain itself.
    – gbn
    Commented Feb 1, 2012 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.