Solved

Using batch FOR loop

Posted on 2004-04-28
3
2,177 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now