Changing a msdhcp scope’s IP range using netsh in batch file

10 Jun

This batch file will:

  • dump the current scope’s definition
  • Extract the line to “add iprange”
  • remove existing iprange
  • add the new iprange

You need 4 parameters: dhcp server ip, scope, new start range, new end range

netsh dhcp server %1 scope %2 dump > temp_%2.txt

find temp_%2.txt /i “add iprange” | find /i “dhcp server” > temp_%2_1.txt

for /f “tokens=1,2,3,4,5,6,7,8,9 delims= ” %%a in (temp_%2_1.txt) do _
netsh dhcp server %1 scope %2 delete iprange %%h %%i

netsh dhcp server %1 scope %2 add iprange %3 %4

Leave a comment

Posted by on June 10, 2011 in Scripts, Windows, Windows CMD


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: