Search DHCP Scopes for a MAC – PowerShell Script

Search DHCP Scopes for a MAC – PowerShell Script

https://ift.tt/7JQFzDR

Just a quick script that will prompt you for a MAC address and then search all DHCP server scopes for that value. You can input the MAC in any common format. Enjoy!

$DHCPServer = "DHCP-SERVER-NAME"

$InputMAC = Read-Host "Enter MAC Address"

# Remove any non-alphanumeric characters from the input MAC address
$FormattedMAC = $InputMAC -replace '[^0-9a-fA-F]', ''

# Format the MAC address as XX-XX-XX-XX-XX
$FormattedMAC = $FormattedMAC -replace '(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})', '$1-$2-$3-$4-$5-$6'

$Scopes = Get-DHCPServerv4Scope -ComputerName $DHCPServer

foreach ($Scope in $Scopes) {
    Get-DHCPServerv4Lease -ComputerName $DHCPServer -ScopeId $Scope.ScopeId | Where-Object {$_.ClientId -EQ $FormattedMAC} | Format-Table -AutoSize
}

System Center

via DeployHappiness https://ift.tt/wZEaIp3

March 8, 2024 at 08:26PM
Joseph Moody