DHCP – Find Duplicate MAC Reservations from 2012 R2 DHCP Server

The following code scans all scopes on a DHCP server and returns any reservations that have the same MAC address

#
<#
.Synopsis
   The following code scans all scopes on a DHCP server and returns any reservations that have the same MAC address
.DESCRIPTION
   The following code scans all scopes on a DHCP server and returns any reservations that have the same MAC address
.SOURCE
   http://britv8.com/dhcp-find-duplicate-mac-reservations-from-2012-r2-dhcp-server/
#>
<#
.Synopsis
   Gets list of scopes and their reservations from a DHCP Server
.DESCRIPTION
   Gets list of scopes and their reservations from a DHCP Server and outputs it to out-gridview.
   You can then select all and copy and paste into execl and do what ever you want
.SOURCE
    http://britv8.com
#>

#Get all the scopes in the Primary Server
# Modify $PrimaryDHCPServer to the name of your DHCP server
$ListofScopesandTheirReservations = @()
$PrimaryDHCPServer = "2012-DHCP3"
$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

}
$DuplicateMACReservations  = $ListofSCopesandTheirReservations| group ClientId | where{$_.count -ge 2}

foreach ($item in $DuplicateMACReservations)
{
 $item.group
}
#

 

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.