Solved

Using batch FOR loop

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

22 Experts available now in Live!

Get 1:1 Help Now