DHCP scopes: Examine their utilization with this PowerShell script

Whether or not you have got carried out Windows DHCP servers or a third-party DHCP server, it’s vital to watch the utilization of DHCP scopes. Whereas Microsoft offers System Middle Operations Supervisor and vital administration packs to watch all facets of DHCP servers together with monitoring of DHCP scopes, the System Middle suite may be very costly and it requires a substantial period of time to implement all of its parts simply to allow monitoring of some servers. On this article, we find out how we will use easy PowerShell instructions and a PowerShell script to test the utilization of DHCP scopes on a number of DHCP servers.

Issues if DHCP scopes are usually not monitored

The DHCP service is without doubt one of the parts many directors configure and neglect. You may run out of IP addresses leading to a declining distribution of IP addresses to purchasers. You will need to at all times monitor DHCP scopes to make sure you have loads of IP addresses accessible to serve purchasers. One other essential cause for monitoring DHCP scopes is that the general operate of a DHCP server is to distribute IP addresses to purchasers so purchasers can talk over the community. Lastly, your goal as an administrator is to at all times search for methods to lower downtime of DHCP providers and detect safety dangers.

Monitoring DHCP scopes on a single DHCP Server

Microsoft offers the Get-DhcpServerv4ScopeStatistics PowerShell cmdlet to supply monitoring knowledge for all scopes on a DHCP server. To get monitoring knowledge for all scopes on a DHCP server, merely execute this PowerShell command:

$ThisServerNow = DHCPServer1.techthan.com
$outcomes=Get-DhcpServerv4ScopeStatistics -ComputerName $ThisServerNow | Choose ScopeID, AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress

The command lists all scopes hosted on DHCPServer.techthan.com and offers info equivalent to scope ID, addresses free, addresses in use and proportion in use.

Accumulating DHCP scopes monitoring outcomes from a number of DHCP servers

To gather DHCP scopes monitoring outcomes from a number of DHCP Servers, you’ll be required to make use of the ForEach loop and likewise point out all DHCP laptop names in a textual content file utilized by the PowerShell script defined within the later part of this text.


Earlier than you may run the PowerShell script supplied within the later part of this text, meet the necessities listed beneath:

  • You’ve gotten put in DHCP PowerShell cmdlets on the pc from the place you intend to run the script.
  • You’ve gotten collected all DHCP server names or IP addresses to be checked by the script and specified within the C:TempDHCPServers.TXT file.
  • All DHCP servers laid out in C:TempDHCPServers.TXT file are reachable from the pc from the place you intend to run the script.
  • Your at the moment logged on account has permissions to entry properties of DHCP servers.

What does the script do?

The PowerShell script performs the next operations:

  • Imports DHCP server PowerShell cmdlets into the present PowerShell session.
  • Checks all DHCP servers talked about within the C:TempDHCPServers.TXT file.
  • Connects to every DHCP server utilizing Get-DhcpServerv4ScopeStatistics and collects the DHCP scopes monitoring knowledge.
  • Checks the DHCP scopes monitoring knowledge for every scope and appends into C:TempDHCPScopesStatus.CSV file.

The PowerShell script

$LocAppDataNow = "C:UsersPublic"
Take away-Merchandise $TestCSVFile -ErrorAction SilentlyContinue
$ThisString="DHCP Server, Scope ID, Percentage Used, Final Status"
Add-Content material "$TestCSVFile" $ThisString
$DHCPServerFile = "C:TempDHCPServers.TXT"
$AnyGap = "No"
ForEach ($Server in GC $DHCPServerFile)
$ThisServerNow = $Server
$TotScopeNotInUse = zero
$TotScopeInUse = zero
$outcomes=Get-DhcpServerv4ScopeStatistics -ComputerName $ThisServerNow | Choose ScopeID,AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress
IF ($Error.Depend -eq zero)


IF ($AnyGap -eq "Yes")

$TestText="HIGH ISSUE"



As soon as the script has completed executing, the output will seem within the C:TempDHCPScopesStatus.CSV file. As you may see within the output generated beneath, the script checked seven DHCP Servers hosted in techthan.com area and two DHCP servers have two scopes hosted which have been used 85 p.c and 90 p.c respectively. As you may see within the Last Standing column additionally exhibits “Not OK” for these two scopes.

DHCP Scopes

Necessary: There are numerous different DHCP checks it is best to carry out to maintain DHCP servers wholesome and operational. The above PowerShell script was obtained from DynamicPacks IT Health Profiler Model, which is able to doing an entire well being evaluation of DHCP servers and supply a report that incorporates suggestions to repair the DHCP-related points. In DynamicPacks IT Profiler, you may see outcomes for all DHCP gadgets in a single console as proven within the screenshot beneath, which is taken from IT Profiler Abstract console:

DHCP Scopes

Now you understand why you will need to monitor the DHCP scopes. We supplied some PowerShell instructions to test DHCP scopes on a single DHCP server and a PowerShell script to watch DHCP scopes on a number of DHCP servers.

Featured picture: Shutterstock

Publish Views:

Extra PowerShell Fundamentals articles

Learn Subsequent

About the Author

Leave a Reply

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