none
How to Automatically set DHCP Option 15 to multiple existing DHCP Scopes RRS feed

  • Question

  • Hello,

    Ihope I have reached the correct forums.

    I have over 300 DHCP Scopes that now need to include option 15. I am looking for a way to automatically add this option to all scopes. Any insight would be greatly appreciated.

    Thank you

    Wednesday, December 11, 2013 5:38 PM

Answers

  • The reason I posted a link to the documentation was because it is up to you to learn how to use the tool.

    Here is the command but you need to learn how to create a script file to feed the NETSH command.  It is in the help.

    Here is a starter:

    netsh dhcp server scope 192.168.1.0 set optionvalue 015 string testnet.local


    ¯\_(ツ)_/¯

    • Marked as answer by fefab Wednesday, December 11, 2013 6:55 PM
    Wednesday, December 11, 2013 6:22 PM
  • First I would use PowerSHell and a file list of scopes to be altered.

    Get-Content scopes.txt | %{
        netsh dhcp server scope $_ set optionvalue 015 string mydomain.net
    }

    That's all it takes.

    If you have WS2012R2 you can use the DHCP Cmdlets in PowerSHell V4.


    ¯\_(ツ)_/¯

    • Marked as answer by fefab Wednesday, December 11, 2013 6:55 PM
    Wednesday, December 11, 2013 6:40 PM

All replies

  • There is a command line utility for DHCP settings:

    netsh dhcp

    Read the help on how to get and set options.  Post in the platform forum for your server.

    Note that all scopes inherit from the global scope.  If you set it at a global level all scopes will contain that option through inheritance.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 5:47 PM
  • Here are the DHCP commands:
    http://technet.microsoft.com/en-us/library/cc787375(v=ws.10).aspx#BKMK_setopval2

    use netsh dhcp server set optionvalue

    This will set the option for all scopes on the server.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, December 11, 2013 6:04 PM
    Wednesday, December 11, 2013 5:52 PM
  • You should also note that the DNSDomainName is set by the domain controller when you join the domain.  It usually doesn't want to be set.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 5:59 PM
  • Perhaps i should have asked How to add this to multiple different specific scopes 
    Wednesday, December 11, 2013 6:08 PM
  • Perhaps i should have asked How to add this to multiple different specific scopes 

    Just add it to the server scope.  It will be added to all existing scopes.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 6:17 PM
  • The reason I posted a link to the documentation was because it is up to you to learn how to use the tool.

    Here is the command but you need to learn how to create a script file to feed the NETSH command.  It is in the help.

    Here is a starter:

    netsh dhcp server scope 192.168.1.0 set optionvalue 015 string testnet.local


    ¯\_(ツ)_/¯

    • Marked as answer by fefab Wednesday, December 11, 2013 6:55 PM
    Wednesday, December 11, 2013 6:22 PM
  • ok thank you. i have done similar using the netsh dhcp commands for creating scopes modifying and adding values.  However, each time i needed to enter the ip address manually on the script for the scope i wanted to change. ie.

    REM -- Create scope 10.72.108.0 on DHCP server 10.70.136.47     

          netsh dhcp server 10.70.136.47 add scope 10.72.108.0   255.255.255.192 "US0305"     

          REM     

          REM -- Assign address range 10.72.108.10 to 10.72.108.20   to new scope
         
          netsh dhcp server 10.70.136.47 scope 10.72.108.0 add   iprange 10.72.108.10 10.72.108.20                

          REM

          REM -- Configure scope option 003 to assign default gateway of 10.72.82.1 to clients

          netsh dhcp server 10.70.136.47 scope 10.72.108.0 set optionvalue 003 IPADDRESS 10.72.108.1

          REM         

          REM -- Configure scope option 006 DNS Server

          netsh dhcp server 10.70.136.47 scope 10.72.108.0 set optionvalue 006 IPADDRESS 10.70.130.11 10.70.136.12 10.61.100.103

      i wanted to know if there was a way to enter all the scope ranges in one .bat file and run it once rather than go in each time and find and replace existing range to reflect the new one.

    I hope that makes sense 

    Wednesday, December 11, 2013 6:35 PM
  • First I would use PowerSHell and a file list of scopes to be altered.

    Get-Content scopes.txt | %{
        netsh dhcp server scope $_ set optionvalue 015 string mydomain.net
    }

    That's all it takes.

    If you have WS2012R2 you can use the DHCP Cmdlets in PowerSHell V4.


    ¯\_(ツ)_/¯

    • Marked as answer by fefab Wednesday, December 11, 2013 6:55 PM
    Wednesday, December 11, 2013 6:40 PM
  • Thank you very much for your prompt responses. Unfortunatley, I am not that familiar with powershell as of yet. I will most likely wind up doing it manually as I am a bit pressed for time to make this change.

    Thank you so much for your help

     
    Wednesday, December 11, 2013 6:49 PM
  • I don't understand.  Create the file and just type in the answer at a powershell prompt and you are done.  10 minutes.

    You can dump the scope names by running netsh dhcp server show scope


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 7:13 PM
  • Im really sorry but i am now confused and lost regarding your two last responses.

    "Get-Content scopes.txt | %{
        netsh dhcp server scope $_ set optionvalue 015 string mydomain.net
    }" &

    Create the file and just type in the answer at a powershell prompt and you are done.  10 minutes.

    You can dump the scope names by running netsh dhcp server show scope"

    what file am i creating and dumping

    Wednesday, December 11, 2013 7:36 PM
  • Ok so this is partial export. i need to change all that are on the .0 network to include option 15 10.73.0.0 - 255.255.255.192-Active -US0123 -Scope for Hart 10.73.0.128 - 255.255.255.224-Active -US0123 Security VLAN -VLAN 3 - Secur 10.73.2.0 - 255.255.255.192-Active -US0124 -Scope for Hart 10.73.2.128 - 255.255.255.224-Active -US0124 Security VLAN -VLAN 3 - Secur 10.73.4.0 - 255.255.255.192-Active -US0125 -US Shop 0125 10.73.4.128 - 255.255.255.224-Active -US0125 Security VLAN -VLAN 3 - Secur 10.73.6.0 - 255.255.255.192-Active -US0126 -Scope for Hart 10.73.6.128 - 255.255.255.224-Active -US0126 Security VLAN -VLAN 3 - Secur 10.73.8.0 - 255.255.255.192-Active -US0127 -Scope for Hart 10.73.8.128 - 255.255.255.224-Active -US0127 Security VLAN -VLAN 3 - Secur 10.73.10.0 - 255.255.255.192-Active -US028 -US Shop 0128 10.73.10.128 - 255.255.255.224-Active -US0128 Security VLAN -VLAN 3 - Secur 10.73.12.0 - 255.255.255.192-Active -US0129 -US Shop 0129 10.73.12.128 - 255.255.255.224-Active -US0129 Security VLAN -VLAN 3 - Secur
    Wednesday, December 11, 2013 7:51 PM
  • The simple two line script takes a file with a list of scopes.  scopes are named by the IP.  192.168.0.1 would be the scope name for a scope starting at that address.

    The simple script red the file a line at a time and passes it to the copmmand until there are no more lines in the file.net

    netsh dhcp server show scope

    will dump the scopes to a file.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 7:54 PM
  • Ok so this is partial export. i need to change all that are on the .0 network to include option 15 10.73.0.0 - 255.255.255.192-Active -US0123 -Scope for Hart 10.73.0.128 - 255.255.255.224-Active -US0123 Security VLAN -VLAN 3 - Secur 10.73.2.0 - 255.255.255.192-Active -US0124 -Scope for Hart 10.73.2.128 - 255.255.255.224-Active -US0124 Security VLAN -VLAN 3 - Secur 10.73.4.0 - 255.255.255.192-Active -US0125 -US Shop 0125 10.73.4.128 - 255.255.255.224-Active -US0125 Security VLAN -VLAN 3 - Secur 10.73.6.0 - 255.255.255.192-Active -US0126 -Scope for Hart 10.73.6.128 - 255.255.255.224-Active -US0126 Security VLAN -VLAN 3 - Secur 10.73.8.0 - 255.255.255.192-Active -US0127 -Scope for Hart 10.73.8.128 - 255.255.255.224-Active -US0127 Security VLAN -VLAN 3 - Secur 10.73.10.0 - 255.255.255.192-Active -US028 -US Shop 0128 10.73.10.128 - 255.255.255.224-Active -US0128 Security VLAN -VLAN 3 - Secur 10.73.12.0 - 255.255.255.192-Active -US0129 -US Shop 0129 10.73.12.128 - 255.255.255.224-Active -US0129 Security VLAN -VLAN 3 - Secur

    You lost all of the formatting.  A dump will list the scopes as aq table.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 7:56 PM
  •  10.73.0.0      - 255.255.255.192-Active        -US0123               -Scope for Hart
     10.73.0.128    - 255.255.255.224-Active        -US0123 Security VLAN -VLAN 3 - Secur
     10.73.2.0      - 255.255.255.192-Active        -US0124               -Scope for Hart
     10.73.2.128    - 255.255.255.224-Active        -US0124 Security VLAN -VLAN 3 - Secur
     10.73.4.0      - 255.255.255.192-Active        -US0125               -US Shop 0125
     10.73.4.128    - 255.255.255.224-Active        -US0125 Security VLAN -VLAN 3 - Secur
     10.73.6.0      - 255.255.255.192-Active        -US0126               -Scope for Hart
     10.73.6.128    - 255.255.255.224-Active        -US0126 Security VLAN -VLAN 3 - Secur
     10.73.8.0      - 255.255.255.192-Active        -US0127               -Scope for Hart
     10.73.8.128    - 255.255.255.224-Active        -US0127 Security VLAN -VLAN 3 - Secur
     10.73.10.0     - 255.255.255.192-Active        -US028                -US Shop 0128
     10.73.10.128   - 255.255.255.224-Active        -US0128 Security VLAN -VLAN 3 - Secur
     10.73.12.0     - 255.255.255.192-Active        -US0129               -US Shop 0129
     10.73.12.128   - 255.255.255.224-Active        -US0129 Security VLAN -VLAN 3 - Secur
     10.73.14.0     - 255.255.255.192-Active        -US0130               -
     10.73.14.128   - 255.255.255.224-Active        -US0130 Security VLAN -VLAN 3 - Secur
    Wednesday, December 11, 2013 7:57 PM
  • So all in the .0 network are the ones i need to modify. there are way more but just as an example
    Wednesday, December 11, 2013 8:00 PM
  • Using NETSH this is the scope table that you want to use:

    NETSH DHCP SERVER SHOW SCOPE > scopes.txt

    ==============================================================================
     Scope Address  - Subnet Mask    - State        - Scope Name          -  Comment  
    ==============================================================================

     192.168.1.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.2.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.3.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.4.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.5.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.6.0    - 255.255.255.0  -Active        -TESTNET.local        -             
     192.168.7.0    - 255.255.255.0  -Active        -TESTNET.local        -             

     Total No. of Scopes = 1
    Command completed successfully.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 8:06 PM
  •  10.73.0.0      - 255.255.255.192-Active        -US0123               -Scope for Hart
     10.73.0.128    - 255.255.255.224-Active        -US0123 Security VLAN -VLAN 3 - Secur
     10.73.2.0      - 255.255.255.192-Active        -US0124               -Scope for Hart
     10.73.2.128    - 255.255.255.224-Active        -US0124 Security VLAN -VLAN 3 - Secur
     10.73.4.0      - 255.255.255.192-Active        -US0125               -US Shop 0125
     10.73.4.128    - 255.255.255.224-Active        -US0125 Security VLAN -VLAN 3 - Secur
     10.73.6.0      - 255.255.255.192-Active        -US0126               -Scope for Hart
     10.73.6.128    - 255.255.255.224-Active        -US0126 Security VLAN -VLAN 3 - Secur
     10.73.8.0      - 255.255.255.192-Active        -US0127               -Scope for Hart
     10.73.8.128    - 255.255.255.224-Active        -US0127 Security VLAN -VLAN 3 - Secur
     10.73.10.0     - 255.255.255.192-Active        -US028                -US Shop 0128
     10.73.10.128   - 255.255.255.224-Active        -US0128 Security VLAN -VLAN 3 - Secur
     10.73.12.0     - 255.255.255.192-Active        -US0129               -US Shop 0129
     10.73.12.128   - 255.255.255.224-Active        -US0129 Security VLAN -VLAN 3 - Secur
     10.73.14.0     - 255.255.255.192-Active        -US0130               -
     10.73.14.128   - 255.255.255.224-Active        -US0130 Security VLAN -VLAN 3 - Secur

    That is wrapped.  DId yo copy it from notepad with word wrp on?

    If so then that is a good starting file.

    We want the first set of numbers on each line.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 8:08 PM
  • Assuming file is called "scopes.txt" then this command gets all IP addresses:

    cat scopes.txt|%{$_.Trim()}|%{$_.Split(' ')[0]}


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, December 11, 2013 8:11 PM
    Wednesday, December 11, 2013 8:11 PM
  • Oh - and only trhe "zero" net.

    cat scopes.txt|
         %{  $_.Trim()  } |
         %{  $_.Split(' ')[0]  }|
         ?{   $_.Split('.')[3] -eq 0 }

    Now you have everything needed to pupm the NETSH command.  Just add teh line I posted above and you are set.

    Test it on a few addresses like maybe three.  Be sure that it looks like what you want.  ONce you see how it works you can unleash on a cast of thousands (or hundreds).

    Dump the server first. Dump after and do a text compare of the two files.  You should see only the changes.  Be sure to do a full backup before starting just in case.


    ¯\_(ツ)_/¯

    Wednesday, December 11, 2013 8:17 PM