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 off
if \{%1\}

\{\} goto syntax
if not exist %1 goto syntax
set batch=%1
set type=u
if /i "%2"

"/c" set type=c
for /f "Tokens=1*" %%i in ('reg -lv "\MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Domain"') do set domain="%%j"
set domain=%domain:"=%
for /f "Skip=2 Tokens=*" %%i in ('showmbrs "\\%domain%\Domain Users"') do call :parse "%%i"
goto end
@echo Syntax: DUaccts Batfile \[/c\]
goto end
set parsed=%1
set parsed=%parsed:"=%!
set work=%parsed:$!=%
if "%type%"

"c" goto cn
if not "%parsed%"

"%work%" goto end
set parsed=%parsed:!=%
call %batch% "%parsed%"
goto end
if "%parsed%"=="%work%" goto end
call %batch% "%work%"

Here is a simple example of a batch you can write to display computer accounts in your domain:

DUaccts c:\folder\listca.bat /c

where c:\folder\listca.bat contains:

@echo off
set param=%1
set param=%param:"=%
@echo %param%