0

DHCP SCOPES: CHECK YOUR OPERATION WITH THIS POWERSHELL SCRIPT

Whether you have got enforced Windows DHCP servers or a third-party DHCP server, it’s necessary to watch the use of DHCP scopes. Whereas Microsoft provides System Center Operations Manager and necessary management packs to watch all aspects of DHCP servers as well as observation of DHCP scopes, the System Center suite is incredibly costly and it needs a substantial quantity of your time to implement all of its elements simply to alter observation of a number of servers. During this article, we tend to find out how we are able to use easy PowerShell commands and a PowerShell script to envision the use of DHCP scopes on multiple DHCP servers.

Problems if DHCP scopes aren’t monitored:
The DHCP service is one amongst the elements several directors tack together and forget. you would possibly run out of IP addresses leading to a declining distribution of IP addresses to shoppers. you want to continually monitor DHCP scopes to make sure you have got many IP addresses out there to serve shoppers. Another vital reason for observation DHCP scopes is that the perform of a DHCP server is to distribute IP addresses to shoppers thus shoppers will communicate over the network. Finally, your objective as associate degree administrator is to continually hunt for ways in which to decrease period of DHCP services and observe security risks.

Monitoring DHCP scopes on one DHCP Server:
Microsoft provides the Get-DhcpServerv4ScopeStatistics PowerShell cmdlet to supply observation knowledge for all scopes on a DHCP server. to urge observation knowledge for all scopes on a DHCP server, merely execute this PowerShell command:

$ThisServerNow = DHCPServer1.Solutionviews.com
$results=Get-DhcpServerv4ScopeStatistics
-ComputerName $ThisServerNow | Select ScopeID,
AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress

The command lists all scopes hosted on DHCPServer.Solutionviews.com and provides data like scope ID, addresses free, addresses in use and share in use.

Collecting DHCP scopes observation results from multiple DHCP servers:
To collect DHCP scopes observation results from multiple DHCP Servers, you’ll be needed to use the ForEach loop and additionally mention all DHCP pc names during a computer file utilized by the PowerShell script explained within the later section of this text.

Requirements:
Before you’ll run the PowerShell script provided within the later section of this text, meet the wants listed below:

  • You have put in DHCP PowerShell cmdlets on the pc from wherever you propose to run the script.
  • You have collected all DHCP server names or IP addresses to be checked by the script and per the C:\Temp\DHCPServers.TXT file.
  • All DHCP servers per C:\Temp\DHCPServers.TXT file area unit accessible from the pc from wherever you propose to run the script.
  • Your presently logged on account has permissions to access properties of DHCP servers.

What will the script do?

The PowerShell script performs the subsequent operations:

Imports DHCP server PowerShell cmdlets into the present PowerShell session.
Checks all DHCP servers mentioned within the C:\Temp\DHCPServers.TXT file.
Connects to every DHCP server victimization Get-DhcpServerv4ScopeStatistics and collects the DHCP scopes observation knowledge.
Checks the DHCP scopes observation knowledge for every scope and appends into C:\Temp\DHCPScopesStatus.CSV file.

The PowerShell script:

$LocAppDataNow = "C:\Users\Public"
$CurrentLoc="C:\Temp\"
$UniqueTest="EXCH"
 
$TestCSVFile="C:\Temp\DHCPScopesStatus.CSV"
Remove-Item $TestCSVFile -ErrorAction SilentlyContinue
 
$ThisString="DHCP Server, Scope ID, Percentage Used, Final Status"
Add-Content "$TestCSVFile" $ThisString
 
$DHCPServerFile = "C:\Temp\DHCPServers.TXT"
 
$AnyGap = "No"
 
ForEach ($Server in GC $DHCPServerFile)
{
$ThisServerNow = $Server
$TotScopeNotInUse = 0
$TotScopeInUse = 0
 
$Error.Clear()
$results=Get-DhcpServerv4ScopeStatistics -ComputerName $ThisServerNow | Select ScopeID,AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress
IF ($Error.Count -eq 0)
{
$TotScopeNow = $results.Name.Count
 
ForEach ($EachScope in $Results)
{
IF ($EachScope.PercentageInUse -gt 80)
{
$AnyGap = "Yes"
$STR = $ThisServerNow+","+$EachScope.ScopeID+","+$EachScope.PercentageInUse+",Not Ok"
Add-Content $TestCSVFile $STR
}
else
{
$STR = $ThisServerNow+","+$EachScope.ScopeID+","+$EachScope.PercentageInUse+",Ok"
Add-Content $TestCSVFile $STR
}
}
}
else
{
$STR = $ThisServerNow+", Error Connecting to DHCP Server"
Add-Content $TestCSVFile $STR
}
}
 
IF ($AnyGap -eq "Yes")
{
$TestStatus="High"
$TestText="HIGH ISSUE"
}
else
{
$TestStatus="Passed"
$TestText="MEDIUM ISSUE"
}

Once the script has finished execution, the output can seem within the C:\Temp\DHCPScopesStatus.CSV file. As you’ll see within the output generated below, the script checked seven DHCP Servers hosted in Solutionviews.com domain and 2 DHCP servers have 2 scopes hosted that are used eighty five plc. and ninety plc. severally. As you’ll see within the Final standing column additionally shows “Not OK” for these 2 scopes.

Important: There area unit several alternative DHCP checks you must perform to stay DHCP servers healthy and operational. The on top of PowerShell script was obtained from Dynamic Packs IT Health Profiler Version five.4.1.1, that is capable of doing an entire health assessment of DHCP servers and supply a report that contains recommendations to repair the DHCP-related problems. In Dynamic Packs IT Profiler, you’ll see results for all DHCP things during a single console as shown within the screenshot below, that is taken from IT Profiler outline console:


Asad Mukhtar

Leave a Reply

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