using DSQUERY, I have scripted When.bat to report when a user was created and modified, or to
report the creation and modification of all users.
The syntax for using When.bat is:
When UserName
where UserName is the sAMAccountName of a user, or * for all users.
NOTE: If UserName is *, a When.txt report file is created in the current folder.
NOTE: UserName can contain leading, trailing, and embedded wildcard characters (*).
When.bat contains:
@echo off if \{%1\}==\{\} @echo Syntax: When UserName&goto :EOF setlocal set usr=%1 set usr=%usr:"=% if "%usr%" EQU "*" goto multiple dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%usr%))" -attr sAMAccountName distinguishedName whenCreated whenChanged -limit 999999 endlocal goto :EOF :multiple if exist when.txt del /q when.txt if exist %temp%\when.tm1 del /q %temp%\when.tm1 set title=N set dsq=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%usr%))" -attr sAMAccountName distinguishedName whenCreated whenChanged -limit 999999 for /f "Tokens=*" %%u in ('%dsq%') do set line=%%u&call :out sort %temp%\when.tm1 /o %temp%\when.tm2 @echo %title%>when.txt for /f "Tokens=*" %%u in ('type %temp%\when.tm2') do set line=%%u&call :report if exist %temp%\when.tm1 del /q %temp%\when.tm1 if exist %temp%\when.tm2 del /q %temp%\when.tm2 endlocal goto :EOF :out if "%title%" EQU "N" set title=%line%&goto :EOF @echo %line%>>%temp%\when.tm1 goto :EOF :report @echo %line%>>when.txt
0 comments
Hide comments