Solved

Using batch FOR loop

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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