Site icon DED9

How to Analyze DHCP Server with PowerShell on Windows Servers

DHCP is a network management protocol that assigns an IP address to each device on the network to communicate with others over the network. DHCP manages these settings automatically and centrally, and network administrators do not need to assign IP addresses to all devices manually. DHCP can be implemented in small local and large enterprise networks.

DHCP automatically assigns a new IP to a device that moves on the network. A DHCP server is a critical component of the IT infrastructure in most environments. In addition to monitoring, which ensures basic service availability, you may also want to check the status of IP ranges or leases. PowerShell provides several cmdlets for this purpose.

This article will teach you how to analyze the DHCP server with PowerShell. Stay with us.

Buy Windows virtual server at the best price.

Commands for managing Windows-based DHCP servers are part of the DHCP server module, which can be obtained by installing RSAT for DHCP. The cmdlets listed here are particularly useful for analyzing problems that occur.

How to identify all servers and search their settings

The first step for DHCP analysis is to retrieve a list of servers that provide DHCP service to the network. This is especially important for larger environments with multiple DHCP servers.

The Get-DhcpServerInDC cmdlet does this and is usually called with no parameters.

For further use in other commands, you can store the returned server names in a variable:

$dhcps = (Get-DhcpServerInDC).DNS name

The cmdlet returns a list of DHCP servers registered in Active Directory. Without the IT department’s knowledge, you won’t find DHCP servers connected to the network.

Some basic settings of a DHCP server, such as whether it is a domain member and authorized, can be retrieved with the following command:

Get-DhcpServerSetting -ComputerName <MyDHCP>

This cmdlet also tells you if the data was restored from a backup. This and other information about the database can also be obtained from the following query:

Get-DhcpServerDatabase -ComputerName <MyDHCP>

Get-DhcpServerAuditLog -ComputerName <MyDHCP>

You can find out if logging is enabled for the DHCP service and where the log file is stored.

However, you cannot display the log content with this command. You should evaluate this text file yourself.

MyDHCP>Dedicated cmdlets for IPv4 and IPv6

Most functions of the module are available in two versions. All functions have “4” or “6” in their names because they correspond to IPv4 or IPv6, respectively. So the following examples for IPv4 can be applied to IPv6:

To get DHCP service analysis and statistics for IPv4 in general, you should use the following:

Get-DhcpServerv4Statistics -ComputerName <MyDHCP>

Statistics include numbers you can get by evaluating individual domains, but here is the total for all domains.

Getting IPv4-related statistics for a DHCP server using Get-DhcpServerv4Statistics

Teaching DHCP scopes analysis

Most queries for available IP addresses or general statistics refer to specific domains. You can count them using Get-DhcpServerv4Scope.

For example, if you want to output all the domains of all DHCP servers to see if there is any overlap between them, you can do the following:

$dhcps = (Get-DhcpServerInDC).DNS name $dhcps | for each {Get-DhcpServerv4Scope -ComputerName $_}

To get an overview of the most important digits of a DHCP server’s IPv4 domain, use the following:

Get-DhcpServerv4ScopeStatistics -ComputerName <MyDHCP>

This command tells you what percentage of the range is used and how many addresses are already taken or still available.

Free, assigned, and reserved addresses

Information about free addresses can be obtained with Get-DhcpServerv4FreeIPAddress.

Note: If you retrieve it using only the ScopeID parameter, you will only get the next free address. To check for more available addresses, you must enter a value for NumAddress:

DhcpServerv4FreeIPAddress -ComputerName <MyDHCP> -ScopeId 192.168.0.0 ` -StartAddress 192.168.0.59 -NumAddress 20

Get-DhcpServerv4Lease -ComputerName <MyDHCP> -ScopeId 192.168.0.0

In the output of the above function, you will see the MAC address of the clients and their status as additional information.

In addition to John and already assigned addresses, there are usually addresses reserved for devices with static IPs. These items can be inquired about as follows:

Get-DhcpServerv4Reservation -ComputerName <MyDHCP> -ScopeId 192.168.0.0

Note: If the client cannot get an address, you should check if it appears in the reject list:

Get-DhcpServerv4Filter -ComputerName <MyDHCP>

Conclusion

The DHCP Server module contains 121 commands that not only analyze their settings and status but can also configure the service.

Exit mobile version