• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Think PowerShell

Think PowerShell

PowerShell for IT Pros

  • About
    • Who I Am
    • Why I Blog
    • Privacy Policy
  • Resources
    • More PowerShell Sites
    • Post Series Index
  • Get Help
  • Show Search
Hide Search

Configuring Windows DHCP, Part 1: Installing the DHCP Server Role

Aaron Rothstein · August 14, 2017 · Leave a Comment

Use PowerShell to configure a Windows DHCP server, starting with the installation of the DHCP Server role.

Windows DHCP Server and PowerShell

If you are running an Active Directory network with Active Directory integrated DNS, you are likely also running Windows DHCP server for managing the automatic assignment of IP addresses to network clients. This post is the first in a series of how to install and configure a Windows DHCP Server using PowerShell, which will allow you to author a build script ahead of implementation, as well as handle some transitional activities from a previous Windows DHCP server.

A DHCP Server is a good candidate for using Desired State Configuration, and there is a DSC resource for managing a DHCP server, which we will cover at the tail end of this post series. But first we will demonstrate the usage of the various DHCP server related cmdlets.

DHCP Lab Environment Overview

Below is a diagram of our lab environment:

A diagram of the lab.thinkpowershell.com environment for the DHCP Demo.
lab.thinkpowershell.com: DHCP Demo
  • We have a firewall router (tpslabfw1) which acts as our default gateway and currently provides DHCP services.
  • We have an Active Directory domain controller with integrated DNS (tpslabdc1).
  • We have a workstation that is a DHCP client (tpslabws1).
  • We have our DhcpDemo server which we will be configuring to be the new DHCP server. This server has been assigned a static IP and added to the domain.

Installing the DHCP Server Windows Features

Before we can start configuring DhcpDemo, we need to install the related Windows Features for DHCP Server. Open an elevated PowerShell session and run Get-WindowsFeature to list available DHCP related features:

PS C:\Windows\system32> Get-WindowsFeature -Name *DHCP*

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[ ] DHCP Server                                         DHCP                           Available
        [ ] DHCP Server Tools                           RSAT-DHCP                      Available

We want to install the DHCP Server feature, and it is likely we will want to include the DHCP Server Tools as well. We can either explicitly specify to install the RSAT-DHCP feature, or we can use the -IncludeManagementTools switch:

# Install DHCP Server and explicitly install DHCP Server Tools (RSAT-DHCP)
Install-WindowsFeature -Name DHCP,RSAT-DHCP

# OR #

# Install DHCP Server with -IncludeManagmentTools, which implies to also install DHCP Server Tools (RSAT-DHCP)
Install-WindowsFeature -Name DHCP -IncludeManagementTools

In our example, we will use the second option leveraging the -IncludeManagementTools switch. For this feature install, no server restart is required.

Installing the DHCP Server Windows Feature.
Installing…
PS C:\Windows\system32> Install-WindowsFeature -Name DHCP -IncludeManagementTools

Success Restart Needed Exit Code      Feature Result                               
------- -------------- ---------      --------------                               
True    No             Success        {DHCP Server, Remote Server Administration...

Authorize DHCP Server in Active Directory

When a DHCP Server is installed on an Active Directory domain joined computer, the DHCP Server needs to be authorized in Active Directory before it can start handing out address leases. We use the Add-DhcpServerInDC cmdlet. This cmdlet needs to be ran by a member of Domain Admins. If the cmdlet is ran locally on the DHCP Server, no additional parameters are required, but in the event you are running it on a remote system or for completeness, we can use the DnsName parameter and the name of the new server:

# Authorize new DHCP Server in Active Directory
Add-DhcpServerInDC -DnsName DhcpDemo.lab.thinkpowershell.com

Configuring DHCP Server Relay

There is some required configuration outside of our Windows environment involving our network infrastructure. We need to configure DHCP Server relay settings on our gateway interfaces. In our lab scenario, this setting is on tpslabfw1, our OPNSense firewall router. I will disable the built-in DHCP Server service and set the DHCP Server Relay to 192.168.1.15, the IP of DhcpDemo. You will have to work with your network team or research your own network devices to determine what is required to enable proper DHCP relay.

Enabling OPNSense DHCP Relay.
Enabling OPNSense DHCP Relay.

Next Steps: Ready for configuration

Our server is now ready for configuration to hand out IP addresses to DHCP clients. In the next post, we will cover creating DHCP scopes using PowerShell.

General DHCP, Networking

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Aaron

Think PowerShell

Copyright © 2025 · Monochrome Pro on Genesis Framework · WordPress · Log in