Partager via


Creating reservation for active leases.

Note: In Windows Server 2008 R2, active leases can be converted to reservations by just doing a right click in the DHCP Server management console. :)

 

If anyone is interested…or needs this in the future:

1. Dump all leases:

Netsh dhcp server scope 192.168.1.0 show client

2. import the output (after cutting the first descriptional lines) to an excel file as space delimited file, remove unnecessary infos (i.e. “-” from the MACs and the unnecessary columns), then export to a file so that only the following info is retained in the file:

IP MAC

IP MAC

3. add reservation for all clients: create a script which processes the lines of the output file and executes:

Netsh dhcp server scope 192.168.1.0 add reservedip IP MAC

(here the IP and the MAC should come from the outputfile)

Script to read from file and create reservation (without error checking):

Const TEST_FILE_PATH = "C:ip-mac.txt"

Dim objFileSystemObject

Dim objOurExistingFileStream

Dim strLine

Dim oShell

Dim myComm

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

'Open our file

Set objOurExistingFileStream = objFileSystemObject.OpenTextFile(TEST_FILE_PATH)

Set oShell = WScript.CreateObject ("WSCript.shell")

'Read out the file-content

Do Until objOurExistingFileStream.AtEndOfStream

'each line contains an Ip and a MAC

strLine = objOurExistingFileStream.ReadLine

'Wscript.Echo strLine

myComm = "%COMSPEC% /c Netsh dhcp server scope 192.168.1.0 add reservedip " + strLine +" >>c:DhcpReservation.log"

strLine

oShell.run myComm,,True

Loop

'Close it

objOurExistingFileStream.Close

Set objOurExistingFileStream = Nothing

Set objFileSystemObject = Nothing

Set oShell = Nothing

 

and finally logs will be available at c:DhcpReservation.log for verification & validation.

NOTE: Thanks to Mr.Balint who has shared the Script with US.

-RamaSubbu SK

Comments

  • Anonymous
    January 01, 2003
    Hey Scott, Your wish has been granted :) . You can convert active leases to reservations easily by doing a right click in Windows Server 2008 R2 Beta DHCP Server. Thanks Raunak Pandya DHCP Server Team

  • Anonymous
    July 05, 2007
    thanks, I had a type mismatch vbs error on the final strLine entry. I added 'on error resume next' at the beginning and all worked OK. If you wanted to put a reservation name and description in as well, how do you do this? thanks :-)

  • Anonymous
    January 09, 2009
    Wish List Item:  It would be great if you could just right click on an active lease in the management tool and select "Convert to reservation"!