Thursday, March 06, 2008

MS: Determine The Last Time a User Logged into a Active Directory Domain.

1) Using a graphical user interface

Install the AcctInfo.dll extension to Active Directory Users and Computers, you can view the last logon timestamp.
TIP: AcctInfo.dll can be downloaded from the Microsoft download site:
http://microsoft.com/downloads/details.aspx?FamilyId=7AF2E69C-91F3-4E63-8629-B999ADDE0B9E&displaylang=en
Open the Active Directory Users and Computers snap-in.
In the left pane, right-click on the domain and select Find.
Select the appropriate domain beside In.
Beside Name, type the name of the user you want to modify and click Find Now.
In the Search Results, double-click on the user.
Click the Additional Account Info tab.
View the value for Last-Logon-Timestamp.

2) Using VBScript

This code prints the last logon timestamp for a user.

' ------ SCRIPT CONFIGURATION ------
strUserDN = "" ' e.g. cn=gmusumeci,ou=Users,dc=musumeci,dc=local
' ------ END CONFIGURATION ---------

set objUser = GetObject("LDAP://" & strUserDN)
set objLogon = objUser.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo "Approx last logon timestamp: " & intLogonTime + #1/1/1601#

No comments: