• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

Batchscript that will look in a file to retrieve server names...

How can I run this batchscript that will look in a file for server names rather than using the for loop?

for %%J in ( Server1 Server2 ) do CALL :copynext %%J
goto :Finished

:: %1 comes from the call line, not the command line
set srvnme=%1

ECHO Running Dumpsec: %srvnme%
@echo off
ping -n 10  \\ >NUL

@echo on
dumpsec /rpt=rights /saveas=csv /outfile=%srvnme%.txt /computer=%srvnme%

@echo off

goto :EOF

  • 2
1 Solution
You can use a FOR /F loop.

If all of your server names are in the file SERVERNAMES.TXT you can do:
for %%J in (SERVERNAMES.TXT) do CALL :copynext %%J
Lee W, MVPTechnology and Business Process AdvisorCommented:
You mean:

for /f "Tokens=1" %%a in (filename.ext) Do call :copynext %%a

Lee W, MVPTechnology and Business Process AdvisorCommented:
OF course, I'd probably just condense the whole script:

@echo off
for /f "tokens=1" %%a in (serverlist.txt) do (
    Echo Running Dumpsec: %%a
    Ping -n 10 \\ >NUL
    @echo On
    dumpsec /rpt=rights /saveas=csv /outfile=%%a.txt /computer=%%a
    @echo off
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now