Skip navigation

JSI Tip 1276. Produce a report of the last time a user logged on to any domain controller.


contains UsrStat, 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 off
setlocal
if "%1"

"" goto syntax if "%2"

"" goto syntax goto begin :syntax @echo Syntax: JSIUsrStat File Domain goto end :begin set file=%1 if exist %file% del /q %file% set file=%file:"=% set wrk1=%~DPN1.tm1 set wrk2=%~DPN1.tm2 set 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% endlocal goto end :report set str=%1 set str=%str:"=% if "%luser%"

"" set luser=%str%&goto end if "%luser:~0,20%"

"%str:~0,20%" set luser=%str%&goto end @echo %luser% >> %file% set luser=%str% goto end :parse set str=%1 set 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 :parse1 set user=%1 set name=%2 set last=%3 set 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 parse2 if /i "%last:~1,5%"

"Never" goto end set 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 out if /i "%mon%"

"Feb" set mon=02&goto out if /i "%mon%"

"Mar" set mon=03&goto out if /i "%mon%"

"Apr" set mon=04&goto out if /i "%mon%"

"May" set mon=05&goto out if /i "%mon%"

"Jun" set mon=06&goto out if /i "%mon%"

"Jul" set mon=07&goto out if /i "%mon%"

"Aug" set mon=08&goto out if /i "%mon%"

"Sep" set mon=09&goto out if /i "%mon%"

"Oct" set mon=10&goto out if /i "%mon%"=="Nov" set mon=11&goto out set mon=12 :out @echo %user% %year% %mon% %day% %time% %dayw% %dc% %name% >> %wrk1% goto end :parse2 set dc=%dc:~0,15% :end

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish