I am looking for a reporting utility that I can get last
login and last log off times for a user. I have 3 domain
controllers in my domain so it must search all 3 for last
log off time. Any ideas?????
Using the Active Directory command-line tools, tip 6820 in the 'Tips & Tricks'
at
http://www.jsiinc.com
call LastLogOnOff UserName on off
@echo off
if {%3}=={} @echo Syntax: LastLogOnOff UserName on off&goto :EOF
setlocal
set user=%1
set qry=dsquery * domainroot -filter
"(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%user%))" -attr
lastLogon lastLogoff -limit 0
REM The above 3 lines are 1 line
set on=0
set off=0
for /f "Tokens=*" %%s in ('dsquery server -O RDN') do (
for /f "SKIP=1 Tokens=1,2" %%a in ('%qry% -s "%%s"') do (
call :last %%a %%b
)
)
Call CvtFileTime %on% ondt
Call CvtFileTime %off% offdt
endlocal&set %2=%ondt%&set %3=%offdt%
goto :EOF
:last
if "%on%" LSS "%1" set on=%1
if "%off%" LSS "%2" set off=%2
Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com