DHCP- Find Duplicate Reservations That Have Different IP Addresses – Split Scope

Fundamental problem when you have two dhcp servers and the scopes split, is that human error creeps in and you may get DHCP reservations that have different IP addresses on each server.

Now probably you rarely have DHCP server failures that you cannot fix quite quickly, so you have never noticed this as the lease was not renewed at the time of the failure.

But…

When you come to consolidate the split scopes (say your on 2003) into single scopes (say 2012 R2), you have a problem!

Questions you ask are:

  1. Do I have any reservations that are in the same scope between servers that have different IP addresses
  2. Which IP address is correct?

Well I cannot answer question 2 for you but I can answer the first question.

 

#
$Scopes = Get-DhcpServerv4Scope -ComputerName $PrimaryDHCPServer

#For all scopes in the primary server, get the scope options and add them to $ListofSCopesandTheirReservations
foreach ($IndividualScope in $Scopes)
{

$ListofScopesandTheirReservations += get-DhcpServerv4Reservation -ComputerName $PrimaryDHCPServer -ScopeId  $IndividualScope.ScopeId |select *,@{label=”DHCPServer”; Expression= {$PrimaryDHCPServer}}

}

$PrimaryDHCPServer = "2012-DHCP2"
$Scopes = Get-DhcpServerv4Scope -ComputerName $PrimaryDHCPServer

#For all scopes in the primary server, get the scope options and add them to $ListofSCopesandTheirReservations
foreach ($IndividualScope in $Scopes)
{

$ListofScopesandTheirReservations += get-DhcpServerv4Reservation -ComputerName $PrimaryDHCPServer -ScopeId  $IndividualScope.ScopeId |select *,@{label=”DHCPServer”; Expression= {$PrimaryDHCPServer}}

}
$DuplicateMACReservations  = $ListofSCopesandTheirReservations| group ClientId,scopeid  | where{$_.count -ge 2}
$ListofDuplicates = $NULL
foreach ($item in $DuplicateMACReservations)
{
$ListofDuplicates += $item.group
}
#
$ListofDuplicates | select ClientId,scopeid, ipaddress,Name,Description | Out-GridView
$subsetofduplicates = @()
$subsetofduplicates = $ListofDuplicates| group ClientId,scopeid, ipaddress  | where{$_.count -le 1}

$FinalListDuplicates = $NULL
foreach ($item in $subsetofduplicates)
{
$FinalListDuplicates += $item.group
}
$FinalListDuplicates | select ClientId,scopeid, ipaddress,Name,Description | Out-GridView
#

Leave a comment

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