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:
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”
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
myComm = “%COMSPEC% /c Netsh dhcp server scope 192.168.1.0 add reservedip ” + strLine +” >>c:DhcpReservation.log”
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.