JSI Tip 1403. Keep track of the computer names that are active in your domain.
June 17, 1999
You can use a logon script and a batch script to determine which client computer names are still active in your domain, what servers they get validated against, and which computer names haven't logged on since a specified date (or never logged on).
The code for the logon script requires that you create a share on each logon server, with a share name Computer$. Place one file in this folder (@echo . > \ServerNameComputer$ServerName.lcn) using the proper case of ServerName. Grant a minimum of Change permission on the share and the following NTFS permissions:
EveryoneSpecial Directory Access (RWX)EveryoneSpecial File Access (RWXD)Administrators Full ControlSystemFull Control
For your non-WinNT clients, define %COMPUTERNAME% and %LOGONSERVER% using WINSET.EXE and SETL.
Add the following line to your logon script:
@echo . > %LOGONSERVER%Computer$%ComputerName%.lcn
To generate a report of computer names that have not logged on since YYYYMMDD, in a format similar to:
Computer Name LOGONSERVER LAST LOGONComputer1DC1YYYYMMDDComputer2DC2YYYYMMDDComputer3NoneNeverComputer4DC1YYYYMMDD
run (on a domain controller) CNLL /D:YYYYMMDD DC1 [DC2 DC3 ... DCn]
where DCx are the names of your domain controllers, in their proper case. CNLL.RPT is created in the current folder. CNLL.bat contains:
@echo offsetlocalset param=%1if "%param:~0,1%"
"/" goto wparam :syntax @echo syntax CNLL /D:YYYYMMDD DC1 [DC2 DC3 ...DCn] or CNLL /A DC1 [DC2 DC3 ...DCn] if exist sort*.tmp del /q sort*.tmp if exist cnll.rpt del /q cnll.rpt endlocal goto end :notfnd @echo %url% NOT FOUND goto syntax :wparam if /i "%param:~1,1%"
"A" set rpt=A&goto dc if /i "%param:~1,1%"
"L" set rpt=L&goto dc if /i "%param:~1,2%"
"D:" set rpt=D&goto symd goto syntax :symd set ymd=%param:~3,8% :dc if "%2"
"" goto syntax if exist sort*.tmp del /q sort*.tmp if exist cnll.rpt del /q cnll.rpt for /f "tokens=1,2,3,4* delims=/ " %%i in ('date /t') do set day=%%i&set mm=%%j&set dd=%%k&set yy=%%l if %yy% GTR 99 goto tymd if %yy% GTR 97 set /a yy=19%yy%&goto tymd set /a yy=20%yy% :tymd set td=%yy%%mm%%dd% set bcn= # set bcn=%bcn:~0,25% :get shift if "%1"
"" goto sam set lcn=%1 set lcn=%lcn:"=% set url="\%lcn%Computer$" if not exist %url%*.* goto notfnd set flcn=N for /f "Skip=4 tokens=1-3*" %%i in ('dir %url%*.lcn /ON') do call :cn %%i "%%l" if "%flcn%"
"Y" goto get @echo %lcn%,%td%,%lcn%>> sortin.tmp goto get :cn set cname=%2 set cname=%cname:.lcn=% set cname=%cname:"=% for /f "Tokens=1-3 Delims=/" %%i in ('@echo %1') do call :when %%i %%j %%k goto end :when if "%3"
"" goto end set /a yy=%3 if %yy% GTR 99 goto mymd if %yy% GTR 97 set /a yy=19%yy%&goto mymd set /a yy=20%yy% :mymd if /i "%lcn%" EQU "%cname%" set flcn=Y set fymd=%yy%%1%2 :mymdsrt @echo %cname%,%fymd%,%lcn%>> sortin.tmp goto end :sam regedit /e reg.tmp "HKEY_LOCAL_MACHINESAMSAMDomainsAccountUsersNames" for /f "Tokens=8 Delims=" %%i in (reg.tmp) do call :ismbr %%i del /q reg.tmp sort < sortin.tmp > sortout.tmp del /q sortin.tmp set lcn=Computer Name # set rls=LOGONSERVER # set rymd=LAST LOGON set rcn=%lcn:"=% # set rcn=%rcn:~0,25% set rls=%rls:"=% # set rls=%rls:~0,25% @echo %rcn%%rls%%rymd%>> CNLL.RPT set lcn=" " set acn="X" set rymd=00000000 for /f "Tokens=1-3 Delims=," %%i in (sortout.tmp) do call :report "%%i" %%j "%%k" if "%rpt%"
"L" goto reporte if "%rpt%"
"A" goto reporte if "%rymd%" GTR "%ymd%" goto finish :reporte set rcn=%lcn:"=% # set rcn=%rcn:~0,25% set rls=%rls:"=% # set rls=%rls:~0,25% if "%rymd%"
"00000000" set rymd=Never if "%rpt%"
"A" goto reportf @echo %rcn%%rls%%rymd%>> CNLL.RPT :finish del /q sortout.tmp endlocal goto end :reportf if "%rcn%"
"%acn%" set rcn=%bcn% @echo %rcn%%rls%%rymd%>> CNLL.RPT goto finish :ismbr set tst=%1 set mbr=%tst:$]=% if "%mbr%"
"%tst%" goto end @echo %mbr%,00000000,None>> sortin.tmp goto end :report if /i %lcn%
%1 goto newcn if /i %lcn%
" " goto newcna if "%rpt%"
"L" goto reportit if "%rpt%"
"A" goto reportit if "%rymd%" GTR "%ymd%" goto newcna :reportit set rcn=%lcn:"=% # set rcn=%rcn:~0,25% if "%rcn%"
"%acn%" set rcn=%bcn% set rls=%rls:"=% # set rls=%rls:~0,25% if "%rymd%"
"00000000" set rymd=Never @echo %rcn%%rls%%rymd%>> CNLL.RPT set acn=%lcn:"=% # set acn=%acn:~0,25% goto newcna :newcn if not "%rpt%"
"A" goto newcna if "%rymd%"
"00000000" goto newcna set rcn=%lcn:"=% # set rcn=%rcn:~0,25% if "%rcn%"=="%acn%" set rcn=%bcn% set rls=%rls:"=% # set rls=%rls:~0,25% @echo %rcn%%rls%%rymd%>> CNLL.RPT set acn=%lcn:"=% # set acn=%acn:~0,25% :newcna set lcn=%1 set rymd=%2 set rls=%3 :endTo run a report showing the computer name activity on each DC (most recent), run CNLL /A DC1 [DC2 DC3 ... DCn].
To run a report showing the latest (most recent) computer name activity, run CNLL /L DC1 [DC2 DC3 ... DCn].
About the Author
You May Also Like