Manage multiple DHCP scopes with netsh script

Use a script to change the DNS lookups and Wins lookups options in DHCP on muliple scripts. Using the netsh command this can be done eaisly.

Tools needed…

  1. Some knowledge of the netsh command
  2. A text file with the ip address’s of the scopes to be modified
  3. IP address’s of the DHCP servers to change
  4. And a script of course.

The easiest way to obtain the ip address’s of the scopes to modify is to log onto the DHCP server itself and open your support tools command prompt

Step 1.

Go to netsh command line to understand more on this command. And make sure you create a test subnet to run my scripts agains to make sure this is right for you.

Step 2.

C:\Program Files\Support Tools>netsh dhcp server 172.x.x.x show scope > c:\scope.txt

At the command prompt enter the section above in red (insert the ip address of the DHCP server in place of 172.x.x.x. This will create a text file with the sope info on your c drive.

 

 

You will now want to open scope.txt and clean it up. You only want the IP address’s of the scopes to be changed. the text file should be in the following format

 

Step 3

for /f “tokens=1″ %%a in (c:\scope.txt) DO netsh dhcp server 172.x.x.x scope %%a set optionvalue 006 IPADDRESS DNS_Address_1 DNS_Address_2 DNS_Adress_3

172.x.x.x = Your DHCP server IP address

DNS_Address_#= DNS server IP address’s

Copy the above red text into a text file and save it as scope_edit.bat to the same folder as scope.txt. Run the bat file. This will run through each IP address changing the dns entires. does not append the scope option for DNS it overwrites it. However it will not effect any other options that are currently set.

You can now use the same script to change your wins optin by changing optioncalue 006 to optionvalue 044

 

 Good luck :)

 
 

Comments

One Response to “Manage multiple DHCP scopes with netsh script”

  1. Darren Toews on March 20th, 2009 9:31 pm

    Great Script! I’m wondering, how would I modify it to create a scope and add in a name and comment?

    I’ve tried changing it to this:

    for /f “tokens=1″ %%a in (c:\scopes.txt) DO netsh dhcp server add scope %%a 255.255.255.0 %%b %%c

    but that didn’t work. it ended up naming the scope %b and didn’t add a comment.

    my text file is tab delimited, and is of the format:

    scopeIPAddress scopeName scopeComment

    Any suggestions?

Got something to say?

You must be logged in to post a comment.