The command to exclude an IP range is similar to setting the IP range for a particular DHCP scope. For example, the command
Netsh dhcp server
\\mydhcpserver
scope 192.168.100.0
add excluderange 192.168.100.1
192.168.100.10
would exclude any IP address from 192.168.100.1 through 192.168.100.10 from being assigned by the DHCP server named mydhcpserver. It's important to note that the exclusion range must fall within the IP inclusion range you set earlier because you're only excluding a subset of IP addresses within the IP range for that scope.
A sample command for creating a DHCP reservation is:
Netsh dhcp server
\\mydhcpserver
scope 192.168.100.0
add reservedip 192.168.100.2
00433FBB0023
printerA "test printer" BOTH
This sample command would reserve the IP address 192.168.100.2 for the node with the MAC address 00433FBB 0023. It gives the reservation the name printerA and the comment test printer. BOTH is the client type, indicating that the reservation should work for both DHCP and BOOTP client requests.
Making the Script Work
The CreateDHCPScope script must be executed from a Windows 2003 server due to its dependence on the Netsh dhcp command. It's important to note that the script does no error checking to verify that the scope was created successfully, so I highly recommend that you verify in the DHCP snap-in that the scope you specified when running the script was created successfully. Typically, if the script is unsuccessful in creating a scope, it's because the operator provided an incorrect subnet mask for the network ID of the scope.
As you can see, just a few lines of code can make it much easier to manage your DHCP environment. You can take this code and expand it for your own purposes. For example, for every scope created, a script could create a certain number of "dummy" reservations to accommodate any reservations that might be necessary in the future, such as if a new printer is added to the subnet. You can also back up and migrate DHCP scopes by using the Netsh dhcp export and import subcommands.