JSI Tip 1276. Produce a report of the last time a user logged on to any domain controller.
Jerold Schulman
April 30, 1999
2 Min Read
containsUsrStat, which will produce a multi-domain-controller report, but each domain controller is listed separately. It still requires substantial manual work to find the last logon. JSIUsrStat.bat uses UsrStat to produce the subject report.
The syntax for using JSIUsrStat.bat is:
JSIUsrStat ReportFile DomainName where:
ReportFile is the full path to the output file.
DomainName is your Windows NT domain name.
The following is a report snapshot:
Jennifer 1999 04 28 14:47:45 Wed \JSI01 Jennifer Schulman JERRY 1999 04 29 23:56:58 Thu \JSI02 Jerold Schulman Opalis 1999 04 29 23:39:57 Thu \JSI02 OpalisRobot ULTRABAC 1999 04 29 23:39:38 Thu \JSI01 ULTRABAC
JSIUsrStat.bat contains:
@echo offsetlocalif "%1"
"" goto syntaxif "%2"
"" goto syntaxgoto begin:syntax@echo Syntax: JSIUsrStat File Domaingoto end:beginset file=%1if exist %file% del /q %file%set file=%file:"=%set wrk1=%~DPN1.tm1set wrk2=%~DPN1.tm2set file="%file%"set wrk1="%wrk1%"set wrk2="%wrk2%"if exist %wrk1% del /q %wrk1%set luser=for /f "Tokens=*" %%i in ('usrstat %2') do call :parse "%%i" @echo ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ >> %wrk1%sort %wrk2%del /f /q %wrk1%for /f "Tokens=*" %%i in ('type %wrk2%') do call :report "%%i"del /f /q %wrk2%endlocalgoto end:reportset str=%1set str=%str:"=%if "%luser%"
"" set luser=%str%&goto endif "%luser:~0,20%"
"%str:~0,20%" set luser=%str%&goto end@echo %luser% >> %file%set luser=%str%goto end:parseset str=%1set str=%str:"=%set str=%str: - =No Name#%set str=%str: - =# %set str=%str:# logon=#logon%for /f "Tokens=1-2* Delims=#" %%i in ('@echo %str%') do call :parse1 "%%i" "%%j" "%%k"goto end:parse1set user=%1set name=%2set last=%3set user=%user:"=% #set user=%user:~0,22%set name=%name:"=% #set name=%name:~1,30%set last=%last:"=%set last=%last:~6,25%if /i "%user:~0,9%"
"Users at " set dc=%user:~9,15% # & goto parse2if /i "%last:~1,5%"
"Never" goto endset mon=%last:~5,3%set day=%last:~9,2%set year=%last:~21,4%set time=%last:~12,8%set dayw=%last:~1,3%if /i "%mon%"
"Jan" set mon=01&goto outif /i "%mon%"
"Feb" set mon=02&goto outif /i "%mon%"
"Mar" set mon=03&goto outif /i "%mon%"
"Apr" set mon=04&goto outif /i "%mon%"
"May" set mon=05&goto outif /i "%mon%"
"Jun" set mon=06&goto outif /i "%mon%"
"Jul" set mon=07&goto outif /i "%mon%"
"Aug" set mon=08&goto outif /i "%mon%"
"Sep" set mon=09&goto outif /i "%mon%"
"Oct" set mon=10&goto outif /i "%mon%"=="Nov" set mon=11&goto outset mon=12:out@echo %user% %year% %mon% %day% %time% %dayw% %dc% %name% >> %wrk1%goto end:parse2set dc=%dc:~0,15%:end
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like