Skip navigation

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

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

JSICC <Drive:>\Folder\BatchFile.ext \[parameters\]

where:

<Drive:>\Folder\BatchFile.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:\scripts\batch1.bat two three four "f i v e" six "s e v e n"

c:\scripts\batch1.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:

@echo off
if "%1"

"" goto syntax
if not exist %1 goto syntax
if /i "%~x1"

".bat" goto doit
if /i "%~x1"

".cmd" goto doit
:syntax
@echo Syntax: JSICC <Drive:>\Folder\BatchFile.ext \[parameters\]
goto end
:doit
set sub=%1
for /f "Skip=3 Tokens=1*" %%i in ('net view') do call :machine %%i %2 %3 %4 %5 %6 %7 %8
set sub=
goto end
:machine
if "%1"

"The" goto end
call %sub% %1 %2 %3 %4 %5 %6 %7 %8
: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