Netsh bat file to add scopes in dhcp when using a txt list of name

Discussion in 'Windows Small Business Server' started by acem77, Feb 12, 2007.

  1. acem77

    acem77 Guest

    the proplem is i cant seem to find any info on how to use
    a for /f loop to grab 2 sets of information. mainly i want to grab the
    scopes IP 192.168.1 and the scope name from a premade txt file. while using a
    batch file
    with all the commands to add 400+ scopes in to dhcp.

    i have 99% of everything working great. here is my batch file. i am sure it
    is ugly but it was my 1st real try at this to save some time.
    this does everything right. but id like to grab data from the same txt file
    or another one with the needed scope names.
    as you can see i now have it grab the ip addresses from a txt file.
    if i try to combine 2 for /f loops i get some stuff but it is never correct.



    set w=.1
    set x=.0
    set z=.100
    set y=.254
    set serverscope=serverscope.txt

    FOR /f "tokens=*" %%M in (%serverscope%) do CALL :CHECK "%%M"

    GOTO :EOF

    :CHECK
    SET serverscope=%~1
    SET serverscope=%serverscope: =%

    set dhcpserver=10.194.11.207
    set ip=%serverscope%
    set scope=%ip%%x%
    set scopename=%name%
    set description=%username%_02/12/07
    set iprange_exclude=%ip%%z% %ip%%y%
    set router=%ip%%w%
    set subnet=255.255.255.0

    netsh dhcp server \\%dhcpserver% add scope %scope% %subnet% %scopename%
    %description%
    netsh dhcp server \\%dhcpserver% scope %scope% add iprange %iprange_exclude%
    netsh dhcp server \\%dhcpserver% scope %scope% add excluderange
    %iprange_exclude%
    netsh dhcp server \\%dhcpserver% scope %scope% set optionvalue 51 dword
    2592000
    netsh dhcp server \\%dhcpserver% scope %scope% set optionvalue 003 ipaddress
    %router%
    netsh dhcp server \\%dhcpserver% scope %scope% set state 1
     
    acem77, Feb 12, 2007
    #1
    1. Advertisements

  2. acem77

    Steve Guest

    Doesn't sound like this is on an SBS 2003 box?
     
    Steve, Feb 13, 2007
    #2
    1. Advertisements

  3. Hi

    Thanks for posting in our newsgroup.

    From your description, I know that you want to add scopes to DHCP with a
    bat file. If I am off-base, please don't hesitate to let me know.

    I am sorry that we don't provide technical support for bat file in this
    newsgroup. Please open a new post in our microsoft. public.msdn newsgroup.
    Thanks for understanding.

    If you need further assistance, please don't hesitate to let me know.


    Best regards,

    Robert Li(MSFT)

    Microsoft CSS Online Newsgroup Support

    Get Secure! - www.microsoft.com/security

    =====================================================

    This newsgroup only focuses on SBS technical issues. If you have issues
    regarding other Microsoft products, you'd better post in the corresponding
    newsgroups so that they can be resolved in an efficient and timely manner.
    You can locate the newsgroup here:
    http://www.microsoft.com/communities/newsgroups/en-us/default.aspx

    When opening a new thread via the web interface, we recommend you check the
    "Notify me of replies" box to receive e-mail notifications when there are
    any updates in your thread. When responding to posts via your newsreader,
    please "Reply to Group" so that others may learn and benefit from your
    issue.

    Microsoft engineers can only focus on one issue per thread. Although we
    provide other information for your reference, we recommend you post
    different incidents in different threads to keep the thread clean. In doing
    so, it will ensure your issues are resolved in a timely manner.

    For urgent issues, you may want to contact Microsoft CSS directly. Please
    check http://support.microsoft.com for regional support phone numbers.

    Any input or comments in this thread are highly appreciated.

    =====================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    <From: "Steve" <>
    <References: <>
    <Subject: Re: Netsh bat file to add scopes in dhcp when using a txt list of
    name
    <Date: Mon, 12 Feb 2007 21:40:37 -0800
    <Lines: 65
    <X-Priority: 3
    <X-MSMail-Priority: Normal
    <X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    <X-RFC2646: Format=Flowed; Original
    <X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    <Message-ID: <O9wk#>
    <Newsgroups: microsoft.public.windows.server.sbs
    <NNTP-Posting-Host: pia140-174.pioneernet.net 66.114.140.174
    <Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP06.phx.gbl
    <Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.windows.server.sbs:16672
    <X-Tomcat-NG: microsoft.public.windows.server.sbs
    <
    <Doesn't sound like this is on an SBS 2003 box?
    <
    <<> the proplem is i cant seem to find any info on how to use
    <> a for /f loop to grab 2 sets of information. mainly i want to grab the
    <> scopes IP 192.168.1 and the scope name from a premade txt file. while
    <> using a
    <> batch file
    <> with all the commands to add 400+ scopes in to dhcp.
    <>
    <> i have 99% of everything working great. here is my batch file. i am sure
    <> it
    <> is ugly but it was my 1st real try at this to save some time.
    <> this does everything right. but id like to grab data from the same txt
    <> file
    <> or another one with the needed scope names.
    <> as you can see i now have it grab the ip addresses from a txt file.
    <> if i try to combine 2 for /f loops i get some stuff but it is never
    <> correct.
    <>
    <>
    <>
    <> set w=.1
    <> set x=.0
    <> set z=.100
    <> set y=.254
    <> set serverscope=serverscope.txt
    <>
    <> FOR /f "tokens=*" %%M in (%serverscope%) do CALL :CHECK "%%M"
    <>
    <> GOTO :EOF
    <>
    <> :CHECK
    <> SET serverscope=%~1
    <> SET serverscope=%serverscope: =%
    <>
    <> set dhcpserver=10.194.11.207
    <> set ip=%serverscope%
    <> set scope=%ip%%x%
    <> set scopename=%name%
    <> set description=%username%_02/12/07
    <> set iprange_exclude=%ip%%z% %ip%%y%
    <> set router=%ip%%w%
    <> set subnet=255.255.255.0
    <>
    <> netsh dhcp server \\%dhcpserver% add scope %scope% %subnet% %scopename%
    <> %description%
    <> netsh dhcp server \\%dhcpserver% scope %scope% add iprange
    <> %iprange_exclude%
    <> netsh dhcp server \\%dhcpserver% scope %scope% add excluderange
    <> %iprange_exclude%
    <> netsh dhcp server \\%dhcpserver% scope %scope% set optionvalue 51 dword
    <> 2592000
    <> netsh dhcp server \\%dhcpserver% scope %scope% set optionvalue 003
    <> ipaddress
    <> %router%
    <> netsh dhcp server \\%dhcpserver% scope %scope% set state 1
    <>
    <>
    <>
    <>
    <>
    <
    <
    <
     
    Robert Li [MSFT], Feb 13, 2007
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.