How To Configure DHCP Using Powershell

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 10.10.54.3-254, it sets the subnet to 255.255.255.0. 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 10.10.54.254 -Name "Blogging Lab" -StartRange 10.10.54.3 -SubnetMask 255.255.255.0 -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 "10.10.54.0" -OptionId 066 -Value "10.10.0.45"

Set DHCP Option 67

Set-DhcpServerv4OptionValue -ScopeId "10.10.54.0" -OptionId 067 -Value "\smsboot\x64\wdsnbp.com"

Set Domain Name

Set-DhcpServerv4OptionValue -ScopeId "10.10.54.0" -OptionId 015 -Value "blogginglab.com"

Set DNS Servers

Set-DhcpServerv4OptionValue -ScopeId "10.10.54.0" -DnsServer 10.10.54.4,10.10.54.5

 

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 "10.10.54.0" -IPAddress "10.10.54.45" -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.

Please follow and like us:
0
Comments are closed.