JSI Tip 0962. List the Users for each Logon Script.


Using only native commands, I have scripted a batch file that produces a sorted/formated list of Logon Scripts and the Users who are configured to use them.

JSILScript.bat creates a report file in the following format:

 <NONE>   UserName1   User1 Full Name 
 <NONE>   UserName9   User9 Full Name 
----------------- ----------------- -----------------
 Script1   UserName3   User3 Full Name 
 Script1   UserName5   User5 Full Name 
 Script1   UserName6   User6 Full Name 
----------------- ----------------- -----------------
 Script2   UserName2   User2 Full Name 
 Script2   UserName4   User4 Full Name 
 Script2   UserName7   User7 Full Name 
 Script2   UserName8   User8 Full Name 

To use JSILScript, place it in your path on the PDC:

JSILScript <Drive:>\Folder\OutputFile.Ext

JSILScript.bat contains:

@echo off
if NOT "%1"

"" goto begin :syntax @echo Syntax: JSILScript File goto end :begin set file=%1 if exist %file% del /q %file% set tmpf=%~dpn1.LScript if exist %tmpf% del /q %tmpf% for /f "Skip=6 Tokens=*" %%i in ('net users /domain') do call :parse "%%i" sort %tmpf% del /q %file% set txt= # set txt=%txt:~0,22% for /f "Tokens=1-3 Delims=\" %%i in (%tmpf%) do call :output %%i "%%j" "%%k" del /q %tmpf% set cnt= set str= set substr= set ustr= set txt= set fullname= set file= set ls= set tmpf= goto end :output set ls=%1 set ls=%ls:"=% set ls=%ls% # set ls=%ls:~0,22% if not "%txt%"

"%ls%" @echo ------------------------------------------------------------------------------- >> %file% set txt=%ls:~0,22% set substr=%2 set substr=%substr:"=% set substr=%substr% # set substr=%substr:~0,22% set fullname=%3 set fullname=%fullname:"=% set fullname=%fullname% # set fullname=%fullname:~0,30% @echo %ls% %substr% %fullname% >> %file% goto end :parse set str=#%1# set str=%str:#"=% set str=%str:"#=% if "%str%"

"The command completed successfully." goto end set substr=%str:~0,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end for /f "Tokens=*" %%i in ('net user "%substr%" /domain') do call :parse1 "%%i" set substr=%str:~25,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end for /f "Tokens=*" %%i in ('net user "%substr%" /domain') do call :parse1 "%%i" set substr=%str:~50,25%# set substr=%substr: =% set substr=%substr: #=% set substr=%substr:#=% if "%substr%"

"" goto end for /f "Tokens=*" %%i in ('net user "%substr%" /domain') do call :parse1 "%%i" goto end :parse1 set ustr=%1 set ustr=%ustr:"=% if /i "%ustr:~0,9%" EQU "Full Name" set fullname=%ustr:~29,99% if /i "%ustr:~0,9%" NEQ "Logon scr" goto end set ls="%ustr:~29,99%" if %ls%=="" goto blnk set ls=%ls:A=a% set ls=%ls:B=b% set ls=%ls:C=c% set ls=%ls:D=d% set ls=%ls:E=e% set ls=%ls:F=f% set ls=%ls:G=g% set ls=%ls:H=h% set ls=%ls:I=i% set ls=%ls:J=j% set ls=%ls:K=k% set ls=%ls:L=l% set ls=%ls:M=m% set ls=%ls:N=n% set ls=%ls:O=o% set ls=%ls:P=p% set ls=%ls:Q=q% set ls=%ls:R=r% set ls=%ls:S=s% set ls=%ls:T=t% set ls=%ls:U=u% set ls=%ls:V=v% set ls=%ls:W=w% set ls=%ls:X=x% set ls=%ls:Y=y% set ls=%ls:Z=z% :blnk @echo %ls%\%substr%\%fullname% >> %file% :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