JSI Tip 0923. How do I perform a set of operations for each computer connected to the network?

Jerold Schulman

December 16, 1998

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Write a batch file that accepts the computer name (in \ComputerName format) as the first paramater and up to 7 additional parameters. Then:

JSICC FolderBatchFile.ext [parameters]

where:

FolderBatchFile.ext is the full path to your batch file. Both .BAT and .CMD are acceptable extensions.

[parameters] are optional parameters for your batch.

Example:

JSICC c:scriptsbatch1.bat two three four "f i v e" six "s e v e n"

c:scriptsbatch1.bat will be called with \MachineN two three four "f i v e" six "s e v e n".

where \MachineN will be cycled with each computer currently available on the network.

Because your batch file is called, it may not have an exit command.

JSICC.bat contains:

<p>@echo off<br>if "%1"</p><h1><a name="_goto_syntax_br_if_not_exist_1_goto_syntax_br_if_i_x1_" id="_goto_syntax_br_if_not_exist_1_goto_syntax_br_if_i_x1_">"" goto syntax<br>if not exist %1 goto syntax<br>if /i "%~x1"</a></h1>".bat" goto doit
if /i "%~x1"<h1><a name="_cmd_goto_doit_br_syntax_br_echo_Syntax_JSICC_lt_Drive_gt_Folder_BatchFile_ext_parameters_br_goto_end_br_doit_br_set_sub_1_br_for_f_Skip_3_Tokens_1_i_in_net_view_do_call_machine_i_2_3_4_5_6_7_8_br_set_sub_br_goto_end_br_machine_br_if_1_" id="_cmd_goto_doit_br_syntax_br_echo_Syntax_JSICC_lt_Drive_gt_Folder_BatchFile_ext_parameters_br_goto_end_br_doit_br_set_sub_1_br_for_f_Skip_3_Tokens_1_i_in_net_view_do_call_machine_i_2_3_4_5_6_7_8_br_set_sub_br_goto_end_br_machine_br_if_1_">".cmd" goto doit<br>:syntax<br>@echo Syntax: JSICC <drive:>FolderBatchFile.ext [parameters]<br>goto end<br>:doit<br>set sub=%1<br>for /f "Skip=3 Tokens=1*" %%i in ('net view') do call :machine %%i %2 %3 %4 %5 %6 %7 %8<br>set sub=<br>goto end<br>:machine<br>if "%1"</drive:></a></h1>"The" goto end
call %sub% %1 %2 %3 %4 %5 %6 %7 %8
:end

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like