Because Dhcpmgmt.msc is not available in RSAT for Windows 10, PowerShell is a good option to remotely administer your DHCP server. This post is a collection of the most common PowerShell commands for configuring DHCP in your network.
Avatar

Add the DHCP server object in the Active Directory domain for the specified server and authorize the server service to serve DHCP clients on the network.

Add-DhcpServerInDC -DnsName dhcpserver.test.com -IPAddress 10.1.1.2

Add the security groups DHCP Users and DHCP Administrators to the DHCP server. (DHCP Users have view-only access to the DHCP server, and DHCP Administrators can administer the DHCP server.)

Add-DHCPServerSecurityGroup -ComputerName "DHCPServer"

Set credentials that the DHCP Server service uses to register or deregister client records on a DNS server.

Set-DHCPServerDnsCredential -ComputerName "DHCPServer"

After you issue this command, the cmdlet prompts you to enter the credentials.

Set DHCP server credentials with Set-DhcpServerDnsCredentials

Set DHCP server credentials with Set-DhcpServerDnsCredentials

Add a scope for the IP address range 10.1.1.1 through 10.1.1.254.

Add-DHCPServerv4Scope -EndRange 10.1.1.254 -Name LAN1 -StartRange 10.1.1.1 -SubnetMask 255.255.255.0 -State Active

Set the DHCP server options for DNS server, DNS domain, and router.

Set-DHCPServerv4OptionValue -ComputerName DHCPServer.test.com -DnsServer 10.1.1.2 -DnsDomain test.com -Router 10.1.1.1

To list the configured options, you can use the following command:

Get-DHCPServerv4OptionValue -ComputerName DHCPServer | Format-List

Set the scope options on the specified scope for DNS server, DNS domain, and router.

Set-DHCPServerv4OptionValue -ComputerName DHCPServer.test.com -ScopeId 10.10.10.0 -DnsServer 10.1.1.2 -DnsDomain test.com -Router 10.1.1.1

To list the configured scope options, use this command:

Get-DHCPServerv4OptionValue -ComputerName DHCPServer -ScopeId 10.10.10.0 | Format-List

See which scopes are hosted on your DHCP server.

To see all IPv4 scopes, use this command:

Get-DHCPServerv4Scope

To see all IPv6 scopes, use this command:

Get-DHCPServerv6Scope

Exclude the IP address range from 10.1.1.1 through 10.1.1.5 from the scope 10.1.1.0 on the DHCP server named DHCPServer.

Add-Dhcpserverv4ExclusionRange -ComputerName DHCPServer -ScopeId 10.1.1.0 -StartRange 10.1.1.1 -EndRange 10.1.1.5

Create a reservation for a client.

First, you can get all leases with the following command:

Get-DHCPServerv4Lease -ScopeId 10.1.1.0

The output will look like this:

DHCP server leases

DHCP server leases

If you want to create a reservation for the client with the IP address 10.1.1.8, type this:

Get-DhcpServerv4Lease -ComputerName dhcpserver -IPAddress 10.1.1.8 | Add-DhcpServerv4Reservation -ComputerName dhcpserver

You can also do a bulk import by using a csv file. The csv file should contain the reservations in the following format:

ScopeId,IPAddress,Name,ClientId,Description
10.1.1.0,10.1.1.8,Client1,6a-1b-5c-1d-4e-1f,Reservation Client1
10.1.1.0,10.1.1.9,Client2,6a-2b-5c-2d-2e-4f,Reservation Client2

Save the file to c:\dhcp\ClientReservations.csv and run the following command to import the reservations:

Import-Csv –Path c:\dhcp\ClientReservations.csv | Add-DhcpServerv4Reservation -ComputerName DHCPServer

Disable and enable the created scope.

To disable the created scope, use this command:

Set-DhcpServerv4Scope -ComputerName DHCPServer -ScopeId 10.1.1.0 -State InActive

To enable the scope, only change the value from InActive to Active:

Set-DhcpServerv4Scope -ComputerName DHCPServer -ScopeId 10.1.1.0 -State Active

Remove the created scope from the DHCP server.

Remove-DHCPServerv4Scope -ComputerName DHCPServer -ScopeId 10.1.1.0 -Force

Get DHCP statistics.

You can get statistics from your DHCP server for several values, such as start time, requests, scopes, and much more. To display the statistics, use this command:

Get-DhcpServerv4Statistics -ComputerName DHCPServer

The following screenshot will show you the values you can get with the command.

DHCP server statistics

DHCP server statistics

You can display the same for a scope by using Get-DhcpServerv4ScopeStatistics.

Create an active multicast scope.

This command creates a multicast scope with the defined values:

Add-DhcpServerv4MulticastScope -ComputerName DHCPServer -Name "Multicast_Range1" -StartRange 224.0.0.60 -EndRange 224.0.0.80

Create and remove a Superscope.

To create a Superscope, use this command:

Add-DhcpServerv4Superscope -ComputerName DHCPServer -SuperscopeName "SupScopeLab1" -ScopeId 10.1.1.0, 10.1.2.0

To remove a Superscope, use this command:

Remove-DhcpServerv4Superscope -ComputerName DHCPServer -SuperscopeName "SupScopeLab1"

Add a DHCP option definition to your server.

To add the option definition for WPAD, use this command:

Add-DhcpServerv4OptionDefinition -ComputerName DHCPServer -Name WPAD -OptionId 252 -Type String

Export and import your DHCP server configuration.

To export the configuration of the DHCP server to the specified XML file, use this command:

Export-DHCPServer -ComputerName DHCPServer -File C:\dhcp\dhcp.xml

To import the exported data to another server named DHCPServer2, use this command:

Import-DHCPServer -ComputerName DHCPServer2 -File C:\dhcp\dhcp.xml -BackupPath C:\dhcpbackup\
avatar
2 Comments
  1. Avatar
    Roy 8 years ago

    So, I have these WAPs that are being assigned IPs via DHCP. I’d like to have them grouped all in the same range instead haphazardly throughout my whole scope. is this possible? seems like it would involve some piping and sorting of commands…

  2. Avatar
    Prarthana 10 months ago

    Hi,

    I need to fetch DHCP scope statistics using powershell.
    Please help me to get below informations.
    Description Details
    Total Addresses 254
    In Use 0 (0%)
    Available 254 (100%)
    Addresses Available (this Server’s Pool) 229 (90%)
    Addresses Available (Partner Pool) 25 (9%)
    Addresses granted (this Server’s Pool) 0 (0%)
    Addresses granted (Partner Pool) 0 (0%)

Leave a reply

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

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account