JSI Tip 10496. Which user accounts haven't logged on since YYYYMMDD?

I have scripted LoSince.bat to report user accounts that haven't logged on since a date you specify.

LoSince.bat requires that you implement tip 10492 ยป How can I record logon and logoff information in both the user account description and the computer account description?, and that you download ADFind.exe freeware and place it in a folder that is in your PATH.

The syntax for using LoSince.bat is:


Where YYYYMMDD is the 4 digit year, 2 digit month, and 2 digit day that you specified.

LoSince.bat contains:

@echo off
setlocal EnableDelayedExpansion
if \{%1\}==\{\} goto err
set since=%1
set adfswitch=-csv -csvdelim ";" -nocsvheader -nodn -default -f "&(objectcategory=person)(objectclass=User)"
set adfattr=Name distinguishedName description
for /f "Tokens=1-2* Delims=;" %%a in ('adfind %adfswitch% %adfattr%') do (
 set Name=%%a
 set DN=%%b
 set desc=%%c
 call :test
goto :EOF
@echo Syntax: LoSince YYYYMMDD
goto :EOF
if "!desc:~1,3!" NEQ "ON " goto report
set wrk1=!desc:"=!
set wrk2=%wrk1:OFF =%
if "%wrk1%" EQU "%wrk2%" goto report
if "!desc:~4,8!" GTR "%since%" goto :EOF
@echo !Name!;!DN!

Hide 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.