JSI Tip 1660. Pass each Domain User or ComputerName to your batch file.
September 28, 1999
Using the freeware REG and Resource Kit SHOWMBRS or public domain SHOWMBRS, I have scripted DUaccts.bat to pass each occurance of the selected object to your batch file. The syntax for using DUaccts.bat is:
DUaccts YourBatchFile [/c]
where YourBatchFile is the full path to your batch file and /c causes computer accounts in your domain to be passed, instead of the default Domain Users.
When your write your batch script, you must NOT include an exit statement, so the routine can return to DUaccts.bat to retrieve the next object. The single parameter that is passed to your routine is enclosed in double quotes. To strip it, you can use the following two lines:
set param=%1
set param=%param:"=%
NOTE: If you used the /c option, the computer name does not have the leading \. To insert them, after stripping the double quotes:
set param=\%param%
DUaccts.bat contains:
@echo offsetlocalif {%1}
{} goto syntaxif not exist %1 goto syntaxset batch=%1set type=uif /i "%2"
"/c" set type=c:okfor /f "Tokens=1*" %%i in ('reg -lv "MACHINESystemCurrentControlSetServicesTcpipParametersDomain"') do set domain="%%j"set domain=%domain:"=%for /f "Skip=2 Tokens=*" %%i in ('showmbrs "\%domain%Domain Users"') do call :parse "%%i"endlocalgoto end:syntax@echo Syntax: DUaccts Batfile [/c]endlocalgoto end:parseset parsed=%1set parsed=%parsed:"=%!set work=%parsed:$!=%if "%type%"
"c" goto cnif not "%parsed%"
"%work%" goto endset parsed=%parsed:!=%call %batch% "%parsed%"goto end:cnif "%parsed%"=="%work%" goto endcall %batch% "%work%":end
Here is a simple example of a batch you can write to display computer accounts in your domain:
DUaccts c:folderlistca.bat /c
where c:folderlistca.bat contains:
@echo off
set param=%1
set param=%param:"=%
@echo %param%
About the Author
You May Also Like