Install DHCP SERVER Using PowerShell
PS C:\Users\Administrator> get-command -Module servermanager
CommandType Name ModuleName
———– —- ———-
Alias Add-WindowsFeature ServerManager
Alias Remove-WindowsFeature ServerManager
Function Disable-ServerManagerStandardUserRemoting ServerManager
Function Enable-ServerManagerStandardUserRemoting ServerManager
Cmdlet Get-WindowsFeature ServerManager
Cmdlet Install-WindowsFeature ServerManager
Cmdlet Uninstall-WindowsFeature ServerManager
PS C:\Users\Administrator> Add-WindowsFeature -IncludeAllSubFeature -Name DHCP, RSAT-DHCP
Success Restart Needed Exit Code Feature Result
——- ————– ——— ————–
True Yes SuccessRest… {DHCP Server, Remote Server Administration…
WARNING: You must restart this server to finish the installation process.
WARNING: Windows automatic updating is not enabled. To ensure that your newly-installed role or feature is
automatically updated, turn on Windows Update.
PS C:\Users\Administrator> Get-WindowsFeature *dhcp*
Display Name Name Install State
———— —- ————-
[X] DHCP Server DHCP InstallPending
[X] DHCP Server Tools RSAT-DHCP InstallPending
Get-WindowsFeature
Install-WindowsFeature DHCP -IncludeManagementTools -whatif
Add-WindowsFeature -IncludeAllSubFeature -Name DHCP, RSAT-DHCP
You can install the DHCP server role on Windows server 2012, by running the following PowerShell command.
Install-WindowsFeature –Name DHCP
This would automatically install the DHCP RSAT which includes DHCP MMC, DHCP netsh context and DHCP PowerShell.
If you only wish to install DHCP RSAT, you can run the following command.
Install-WindowsFeature –Name RSAT-DHCP
Next step is to bind the DHCP server to a network interface where it can listen for the client requests and lease out IP addresses. This network interface should be configured with a static IPv4 or IPv6 address. The following PowerShell command would bind the DHCP server to
the network interface.
Set-DhcpServerv4Binding -BindingState $true -InterfaceAlias “Local Area Connection”
If your network operates in Windows domain environment then you will need to authorize the DHCP server in Active Directory so that it can serve IP addresses to client computers. Run the following command to authorize the DHCP server. In this case the IP address of DHCP
server is obtained by looking up in DNS. You can also choose to explicitly specify an IP address of DHCP server.
Add-DhcpServerInDC -DnsName “DhcpServer.DomainName.com”
A scope defines a range of IP addresses that are available to be leased out to client computers on a particular subnet. Here is an example of how to add a new scope through Powershell. The Add-DhcpServerV4Scope cmdlet also gives you options to specify the state of a scope, enable Network Access Protection (NAP), add the scope as part of a superscope and so on.
Add-DhcpServerv4Scope -Name “Friendly Name of Scope” -StartRange 10.10.10.1 -EndRange 10.10.10.254 -SubnetMask 255.255.255.0
In a network that uses DHCP, it is a common requirement to permanently reserve an IP address for specific clients. It is typically needed for devices like printers and application servers that always have a fixed IP address on the network. Here’s how to add a reservation on the DHCP server.
Add-DhcpServerv4Reservation -IPAddress 10.10.10.8 -ClientId F0-DE-F1-7A-11-6A -Description “Friendly name of reservation”
In addition to IP address leases, DHCP server also provides other configuration information to the clients. It can provide the IP address of DNS server, default gateway, router, WINS server and nmore. Network administrator has to define these properties on DHCP server by means of DHCP option values.
With PowerShell you can define :
– A server wide option value which is applicable to all scopes on the DHCP server
– An option value for a specific scope or a reservation
For instance, the following command defines an option value to apply on all scopes.
Set-DhcpServerv4OptionValue -OptionId 6 -value 192.168.1.1
Note: option id 6 is for Dns Server
MAC address filtering is used to define a list of clients that can acquire IP addresses from the DHCP server. Any foreign client that is not on the list will fail to get an IP address. This greatly enhances security of corporate network. You can define two types of MAC Addresses
lists on DHCP servers. The clients in Allow list are provided services by the DHCP server and ones in Deny list are denied the services. Here is how you add a new MAC address to the deny list.
Add-DhcpServerv4Filter -List Deny -MacAddress F0-DE-F1-7A-11-6B -Description “Friendly name of filter”
Remove Windows feature
PS C:\Users\Administrator> Remove-WindowsFeature -Name DHCP, RSAT-DHCP
Success Restart Needed Exit Code Feature Result
——- ————– ——— ————–
True Yes SuccessRest… {DHCP Server, Remote Server Administration…
WARNING: You must restart this server to finish the removal process.
Recent Comments