Skip navigation

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:

LoSince YYYYMMDD

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
)
endlocal
goto :EOF
:err
@echo Syntax: LoSince YYYYMMDD
goto :EOF
:test
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
:report
@echo !Name!;!DN!



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