Found the following script on the web. It works great if you want to get the LastLogonTimeStamp from every object in the OU. What i would like to be able to do is specifiy a "username", search AD, and get the lastlogontimestamp for that user. We run Win2K3 and Win2k8 and would only query one DC.
Can anyone help mod this script to allow for the entry of a single username/logoname/sAMAccountName and get the LastLogonTimeStamp attribute?
Option Explicit
Dim objOU, objUser, objRootDSE, objLastLogon
Dim strContainer, strDNSDomain
Dim intLastLogonTime, intGuyTime
strContainer = "ou=AMER,ou=Regions,"
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
Set objOU = GetObject("LDAP://" & strContainer)
For Each objUser In objOU
Set objLastLogon = objUser.Get("lastLogon")
intLastLogonTime = objLastLogon.HighPart * (2 ^ 32) + objLastLogon.LowPart
intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440
MsgBox objUser.FirstName & " " & objUser.LastName & " 's last logon time: " & intLastLogonTime + #1/1/1601#
Next
Thanks,
Dave Casson
Dave