Using PowerShell to create a DHCP server scope

by Mitch Tulloch [Published on 21 Aug. 2013 / Last Updated on 21 Aug. 2013]

A tip on how you can use Windows PowerShell to create a DHCP server scope.

You can manage Windows Server 2012 DHCP servers using Windows PowerShell. Common DHCP server-management tasks include creating scopes, creating exclusion ranges, creating reservations, configuring scope and server options, and so on.

For example, let’s begin by viewing all the scopes currently configured on the DHCP server:

PS C:\> Get-DhcpServerv4Scope
 
ScopeId      SubnetMask      Name  State   StartRange   EndRange      LeaseDuration
-------            ------------------     ---------  -----   ----------------   ---------------      -------------
172.16.11.0  255.255.255.0   test   Active  172.16.11.35 172.16.11.39  8.00:00:00

Note that there is currently only one active scope on the DHCP server. Now add a second scope for the IP address range 172.16.12.50 through 172.16.11.100. Leave the scope inactive until you finish configuring exclusions and reservations for it:

PS C:\> Add-DhcpServerv4Scope -EndRange 172.16.12.100 -Name test2 `
-StartRange 172.16.12.50 -SubnetMask 255.255.255.0 -State InActive

Note that in this cmdlet it doesn’t matter what order you specify the parameters in because you specified the end of the address range before specifying its beginning.

Running Get-DdhpServerv4Scope again indicates that adding the new scope was successful:

PS C:\> Get-DhcpServerv4Scope
 
ScopeId      SubnetMask      Name   State    StartRange    EndRange      LeaseDuration
-----------      -----------------      ---------   -------    ---------------    ---------------      -------------
172.16.11.0  255.255.255.0   test   Active   172.16.11.35  172.16.11.39  8.00:00:00
172.16.12.0  255.255.255.0   test2  Inactive 172.16.12.50  172.16.12.100 8.00:00:00

Mitch Tulloch is a nine-time recipient of the Microsoft Most Valuable Professional (MVP) award and
a widely recognized expert on Windows administration, deployment and virtualization.  For more information see
http://www.mtit.com. This tip was excerpted from his latest book Training Guide: Installing and Configuring Windows Server 2012 from Microsoft Press.

See Also

Featured Links