Create and Manage DHCP Scopes using PowerShell V4

Managing DHCP with Powershell

Overview

PowerShell is a useful tool to use for scripting server role configurations.  The automation inherit in scripting means we can use it to quickly manage multiple servers in minutes, and we can do it remotely from our desktops. This is great when you have a large environment

This tutorial will guide you through some of the administrative tasks that can be done using PowerShell.

Creating a Scope

Cmdlet and Syntax

The cmdlet used to create new DHCP scopes in Windows Server 2012 R2 is Add-DhcpServerv4Scope. It has the following syntax.

Add-DhcpServerv4Scope [-StartRange]  [-EndRange]  [-SubnetMask]  [-Name]  [-ActivatePolicies  ] [-AsJob] [-CimSession <CimSession[]> ] [-ComputerName  ] [-Delay  ] [-Description  ] [-LeaseDuration  ] [-MaxBootpClients  ] [-NapEnable] [-NapProfile  ] [-PassThru] [-State  ] [-SuperscopeName  ] [-ThrottleLimit  ] [-Type  ] [-Confirm] [-WhatIf] [ ]

Examples of Creating a Scope

  • To create a scope named “Toronto Corporate” with an IP range of 172.30.0.1-254 and a lease duration of 8 days, we would execute the following in PowerShell.
    Add-DhcpServerv4Scope -StartRange 172.30.0.1 -EndRange 172.30.0.254 -SubnetMask 255.255.255.0 -Name "Toronto Corporate" -LeaseDuration 8:00:00
  • To do the same scope shown above, but from a remote computer targeting a DHCP server named dhcp01, we would execute the following.
    Add-DhcpServerv4Scope -Computer dhcp01 -StartRange 172.30.0.1 -EndRange 172.30.0.254 -SubnetMask 255.255.255.0 -Name "Toronto Corporate" -LeaseDuration 8:00:00