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

Using batch FOR loop

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
jcorbin
Asked:
jcorbin
  • 2
1 Solution
 
mrdtnCommented:
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
 
mrdtnCommented:
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
 
sirbountyCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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