X

How to Configure DHCP with PowerShell

PowerShell commands are an easy way to save a lot of time as system administrator. In this article, I'll show you how to configure DHCP from PowerShell. I have following information including scope, and router gateway IP.

DHCP

DNSServerIP="192.168.1.10"
DHCPServerIP="192.168.1.10"
StartRange="192.168.1.150"
EndRange="192.168.1.200"
Subnet="255.255.255.0"
Router="192.168.1.1"

Following is the configuration break down:

  1. Installing DHCP
  2. Adding DHCP scope
  3. Adding DNS server, and router gateway options
  4. Setting lease duration for a scope
  5. Restarting DHCP service

Step-by-Step Instructions

Step 1: Install DHCP Server Role

PowerShell Command:

Install-WindowsFeature -Name 'DHCP' –IncludeManagementTools

Step 2: Add DHCP Scope

PowerShell Command:

Add-DhcpServerV4Scope -Name "DHCP Scope" -StartRange 192.168.1.150 -EndRange 192.168.1.200 -SubnetMask 255.255.255.0

Step 3: Add DNS Server, Router Gateway Options in DHCP

PowerShell Command:

Set-DhcpServerV4OptionValue -DnsServer 192.168.1.10 -Router 192.168.1.1

Step 4: Set Up Lease Duration

PowerShell Command:

Set-DhcpServerv4Scope -ScopeId 192.168.1.10 -LeaseDuration 1.00:00:00

Step 5: Restart DHCP Service

PowerShell Command:

Restart-service dhcpserver

That's all. With 5 PowerShell commands, you installed and configured a complete DHCP server.

Karim Buzdar: About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various websites.
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings