RSS

Tag Archives: netsh

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

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

Advertisements
 
Leave a comment

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

 

Tags: ,

Script to get all active msdhcp client leases using netsh

Here is a quick batch file you can use to get active leases of all scopes for a list of ms dhcp servers. Assuming that you already done a dump using “netsh dhcp server \\host dump” to a file called dhcp_dumps.txt:

find .\dhcp_dumps.txt /i "add scope" | _
find /i "dhcp server" > .\ts.txt
del /q .\getac.txt

for /f "tokens=1,2,3,4,5,6,7 delims= " %%a in (.\ts.txt) do _
@echo dhcp server %%c scope %%f show clients 1 >> getac.txt

netsh -f .\getac.txt > .\ac_list.txt

Note: Updated with a better script

Also note: _ is used as a wrapper for the blog, its not used in the actual script

 
Leave a comment

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

 

Tags: ,