This article will go through the cmdlet to successfully configure DHCP services on a Windows server using Powershell.
Firstly you can start a Powershell session on the DHCP server using the following command: It will prompt for the credential using the Get-Credential command.
Enter-PSSession -ComputerName [DHCPServerName] -Credential (Get-Credential)
Create an IPv4 DHCP Scope for 10.10.10.0 name Ground Floor with range 10-200 on server DC1.domain.com
Add-DhcpServerv4Scope -StartRange “10.10.10.10” -EndRange “10.10.10.200” -SubnetMask “255.255.255.0”-Name “Ground Floor” LeaseDuration [day.hrs:mins:secs]-ComputerName “DC1.domain.com” -Description “Subnet for Data VLAN on Ground Floor” -State [Active/InActive]
Configure the Scope 10.10.10.0 DHCP server DNS, Domain, Gateway, WINS and wpad settings
Add-DhcpServerv4OptionValue -ScopeId 10.10.10.0 -Router 10.10.10.1 -DnsDomain “domain.com” -DnsServer 10.10.10.250 WinsServer 10.10.10.251 -Wpad “http://proxy.domain.com/wpad.dat” -ComputerName “DC1.domain.com”
Note: To configure the options above at the reservation level replace the parameter ReservedIP and for setting it at the server level, exclude both ReservedIP and ScopeId parameters.
Show the DHCP server IPv4 Scope
Get-DhcpServerv4Scope [-ComputerName “DC1.domain.com”] [[-ScopeId] 10.10.10.0]
Change a DHCP Server Scope Settings
Set-DhcpServerv4Scope [-Type [DHCP|Bootp|Both]] [-ScopeId] 10.10.10.0 [-Description “Scope for data vlan for 10.10.10.0“] [-LeaseDuration day.hrs:mins:secs] [-Name “Ground Floor”] [-ComputerName “DC1.domain.com”] -StartRange 10.10.0.20 -EndRange 10.10.10.200
Remove a DHCP server IPv4 Scope
Remove-DhcpServerv4Scope [-ScopeId] 10.10.10.0 [-Force] [-ComputerName “DC1.domain.com”]
Create a reservation for IP address 10.10.10.100 on DHCP server DC1.domain.com
Add-DhcpServerv4Reservation -ScopeId 10.10.10.0 -IPAddress 10.10.10.100 -ClientId [usually-MAC-address] -ComputerName DC1.domain.com -Description “Reservation for Kiosk PC”
Listing the DHCP Server Scope
Get-DhcpServerv4Scope -ComputerName [DHCPServerName] -ScopeId [IPAddress]
Get the List of DHCP Server Options
Get-DhcpServerv4OptionValue -ScopeId [IPAddress][-All -Brief] -ReservedIP [SpecificIP]
Note: Exclude the ReservedIP parameter to list the values at the scope level and exclude ScopeId parameter to list the values at the server level.
Get the interface and IP address that the DHCP server service is bound
Get-DhcpServerv4Binding -ComputerName “DC1.domain.com”
Set the interface that the DHCP server service will be bound
Set-DhcpServerv4Binding -ComputerName “DC1.domain.com” -BindingState $true -InterfaceAlias “Wired Ethernet Connection”
Set the Boot server Host Name (option id ) for the DHCP server scope of 192.168.0.0
Set-DhcpServerv4OptionValue -OptionId 3 -Value 192.168.0.1 -ScopeId 192.168.0.0
List the DHCP server IPv4 address lease
Get-DhcpServerv4Lease -ScopeId 10.10.10.0 [-IPAddress 10.10.10.25] [–ClientId 00-00-fe-3e-b0-01] [-BadLeases] [-AllLeases] -ComputerName “DC1.domain.com”
Note: Using the IPAddress parameter return lease for specific IP address. Using the ClientId parameter returns only lease for client mac. Using the BadLeases returns only bad leases. Using the AllLeases parameter includes all leases including Offered, Declined and Expired.
Removing a DHCP server IPv4 address lease
Remove-DhcpServerv4Lease -ScopeId 10.10.10.0 [-IPAddress 10.10.10.25] -ClientId [00-54-fe-ed-00] [-BadLeases] [-ComputerName “DC1.domain.com”]
Note: same rule applies as the Get cmdlet for this command.
Get ten (10) Free IP Address from the DHCP server from the scope 10.10.10.0 in the range 10.10.10.50-100
Get-DhcpServerv4FreeIPAddress -ScopeId 10.10.10.0 -NumAddress 10 -StartAddress 10.10.10.50 -EndAddress 10.10.10.100
Add a DHCP Scope of IPv4 Excluded Range
Add-DhcpServerv4ExclusionRange [-ComputerName “DC1.domain.com“] [-ScopeId] 10.10.10.0 [-StartRange] 10.10.10.200 [-EndRange] 10.10.10.250
Show the DHCP Scope of IPv4 Address Excluded Range
Get-DhcpServerv4ExclusionRange [-ComputerName “DC1.domain.com“] [[-ScopeId] 10.10.10.0]
Remove an DHCP Scope of IPv4 Address Excluded Range
Remove-DhcpServerv4ExclusionRange [-ComputerName “DC1.domain.com”] [-ScopeId] 10.10.10.0 [[-StartRange] 10.10.10.200] [[-EndRange] 10.10.10.250]
Retrieves the DHCP server scope statistics which includes Free, In Use, Reserved, Pending and Percentage in use IP address
Get-DhcpServerv4ScopeStatistics [[-ScopeId] 10.10.10.0] [-ComputerName “DC1.domain.com”] [-Failover]