How to Configure DHCP Using PowerShell

I have complied some notes on how to install and configure DHCP using Powershell cmdlets.  These can come in handy for setting up lab environments quickly or scripting changes within your environment easily.

The first cmdlet is how to install the necessary role: Install-WindowsFeature -IncludeManagementTools DHCP

Once the DHCP role has been created you can start to configure scopes and various options needed for that scope. The cmdlet below creates a scope with the range, it sets the subnet to And correctly names the scope as "Blogging Lab" and enters an appropriate description as well. It also sets a lease duration of 7 days. Add-DhcpServerv4Scope -EndRange -Name "Blogging Lab" -StartRange -SubnetMask -Description "Blogging Lab DHCP SCope" -LeaseDuration 7.00:00:00

Now that you have a scope set up you can now start to configure the options that it needs:

Set DHCP Option 66 Set-DhcpServerv4OptionValue -ScopeId "" -OptionId 066 -Value ""

Set DHCP Option 67 Set-DhcpServerv4OptionValue -ScopeId "" -OptionId 067 -Value "\smsboot\x64\"

Set Domain Name Set-DhcpServerv4OptionValue -ScopeId "" -OptionId 015 -Value ""

Set DNS Servers Set-DhcpServerv4OptionValue -ScopeId "" -DnsServer,

Occasionally you need to set DHCP reservations for certain devices, such as printers or iLO interfaces, the following cmdlet will help you configure these without the need for the GUI interface: Add-DhcpServerv4Reservation -ScopeId "" -IPAddress "" -ClientId "00-15-B6-A6-FD-FF" -Description “SCCM-Server-ilo” -Name “SCCM01-ilo”

Whenever I find Powershell commands that help to automate or configure something quicker than doing it via a GUI I like to keep a note of them within OneNote. That way I can quickly search through it in the future and re-use them.