So we are in the process of migrating an entire network from one ip.addr range to another, and need to create a large number (>100) of reservations across various scopes at each location. While the GUI DHCP Admin tool is adequate to the task, I didn’t want to have to do that one at a time, especially since I was given an Excel spreadsheet with the required information to create the reservations. I figured there had to be a tool like dnscmd.exe for DHCP. After doing some looking, I only found that there was an old NT ResKit tool dhcpcmd.exe, but I had no interest in using that on my 2008 domain.
I did a little poking around with netsh and figured out a way to do this.
- Create a CSV file with no header. The four columns should include only the following…
scope subnet,ip.addr reservation,mac address (no separator characters),nameFor example, if you wanted to reserve 1.2.3.4/24 for a client named workstation1, with a mac.addr of 00-11-22-33-44-55, your file would look like this…
1.2.3.0,1.2.3.4,001122334455,workstation1
- The following command line will do the trick. If using Vista or 2008, run this from an Administrative cmd prompt.
for /f “tokens=1-4 delims=,” %G IN (list.txt) do netsh dhcp server \\w.x.y.z scope %G add reservedip %H %I %J
To break this down, “tokens=1-4″ means to use all four columns. You could also have said “tokens=*.”
“Delims=,” just means that the delimiting character in the file is a comma.
“%G” sets the first variable…you could have used any letter or number you want as long as you stay in order for the rest.
“list.txt” is of course the name of the CSV file you are going to use.
“netsh dhcp server \\w.x.y.z” executes the command against the dhcp service of server w.x.y.z (you could use an FQDN.)
“scope %G” means to use the scope defined in column A
“add reservedip” means exactly what it says, and that is populated with the values in columns B, C, and D as variables %H %I and %J….ip.addr for mac.addr and name.
Hopefully this will help someone else out…if not, I expect I will need to refer to this again many times over the next few months!
keywords “create dhcp reservations” script “command line” dhcpcmd
You might also enjoy:





{ 5 comments… read them below or add one }
Thane You ,
very nice script , it was help me to move 150 address to reservation
Yossi
You’re very welcome…glad it helped!
Thank you greatly for this, Ed.
For reference, this also worked perfectly on my Windows 2003 server.
Excellent! I’m glad it helped.
Fantastic, saved me about an hour of work today (Server 2k3). Much appreciated!