Scripting out DHCP reservations in Windows Server 2008 with Netsh

Scripting out DHCP reservations can save a lot of time for large pools of reservations. See how the Windows Server 2008 Netsh tool can help out in this regard.

Netsh is one of the most powerful Windows networking tools in the pre-PowerShell era. For Windows Server 2008, Netsh adds new contexts and expands some of the existing functionality introduced in Windows 2000.

One use of Netsh includes some management of DHCP scopes to modify reservations. An area in which this can be very useful is to script out a large batch of reservations for a number of virtual machines for a server subnet or a test scenario. On a Windows Server 2008 system running DHCP, this is the scripted out command to make or modify a reservation:

In this example, the DHCP server name and scope are populated, as well as the desired IP address, the MAC address, and the DNS domain name of the system for the reservation. Once the command is entered, Netsh interacts with the DHCP service on the server to make the appropriate reservation to the scope. Figure A shows the command entered successfully.
Figure A

If an existing reservation needs modification, the existing entry should be sent a sequence of commands that delete the existing reservation and then add the new one. Here's an example:

Netsh finesse can enable many tasks to be completed quickly. Plus, being able to modify many DHCP reservations in a scriptable fashion can save a lot of time during a large scope modification or creation.

Stay on top of the latest Windows Server 2003 and Windows Server 2008 tips and tricks with our free Windows Server newsletter, delivered each Wednesday. Automatically sign up today!

About Rick Vanover

Rick Vanover is a software strategy specialist for Veeam Software, based in Columbus, Ohio. Rick has years of IT experience and focuses on virtualization, Windows-based server administration, and system hardware.

Full Bio

Rick Vanover is a software strategy specialist for Veeam Software, based in Columbus, Ohio. Rick has years of IT experience and focuses on virtualization, Windows-based server administration, and system hardware.

I've been wanting the ability to script dhcp reservations for a long time, so I was really happy when I saw this post.
But... on our W2K8R2 servers, netsh has only the dhcpclient context, no dhcp context.
Any idea what is up with this?

Netsh was delivered starting with Windows 2000. Since then, it has gotten more and more robust, including adding new contexts.
Without doublechecking, I ~~think~~ these commands in this context are new to WS2K8.
Kinda like "the other PowerShell'