Solved

Using batch FOR loop

Posted on 2004-04-28
3
2,211 Views
Last Modified: 2008-03-10
I need to change some options on every DHCP scope for 4 DHCP servers, I thought I could use netsh but have run into a snag;

for /F %%1 in (C:\temp\ServerList.txt) do (

command /c FOR /L %SCOPE IN (1,1,254) DO (

netsh dhcp server \\%%1 scope 192.168.193.%scope% set optionvalue 51 DWORD 5184000
Netsh dhcp server \\%%1 scope 192.168.193.%scope% show optionvalue)
)

The SCOPE variable I would like to increment from 1 - 254 to assign to my last octect of the dhcp scope
0
Comment
Question by:jcorbin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
mrdtn earned 500 total points
ID: 10944601
I'm not familiar with the netsh and what is is doing, but from a DOS perspective, I believe it is clear what the script should do, and the modified version below should be all you need.

Let me know if there are any other issues -- and if this works.  What was your intent on using "COMMAND /C"?  If you want to "spawn" a bunch of seperate shells, there is a way to do it, but I don't believe that's what you want to do.

--

mrdtn

--

@echo off

for /f "tokens=*" %%1 in (c:\ServerList.txt) do (
      for /l %%s in (1,1,254) do (
            netsh dhcp server \\%%1 scope 192.168.193.%%s set optionvalue 51 DWORD 5184000
            Netsh dhcp server \\%%1 scope 192.168.193.%%s show optionvalue)
      )
)
0
 
LVL 6

Expert Comment

by:mrdtn
ID: 10944607
By the way, you can only use single letters for variable names in FOR loops, so I replaced it with "s" among the other changes.

--
mrdtn
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10944615
This should do it for you:

for /f %%x in (c:\temp\serverlist.txt) do (
  for /l %%a in (1,1,254) do (
    netsh dhcp server \\%%x scope 192.168.193.%%a set optionvalue 51 DWORD 5184000
    netsh dhcp server \\%%x scope 192.168.193.%%a show optionvalue
  )
)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question