Skip to content

Instantly share code, notes, and snippets.

@ml4den
Last active January 16, 2025 15:41
Show Gist options
  • Save ml4den/265f17164e39e943a2a90eef0a7966d0 to your computer and use it in GitHub Desktop.
Save ml4den/265f17164e39e943a2a90eef0a7966d0 to your computer and use it in GitHub Desktop.
A quick and dirty PowerShell script to search for a particular MAC address on Windows DHCP servers across all scopes.
# A quick and dirty PowerShell script to search for a particular MAC address on Windows DHCP servers across all scopes.
$dhcpServers = @("dhcp-server-01","dhcp-server-02") # Define your servers here
$results = @()
$clientId = Read-Host -Prompt "Input the MAC address you want to search for"
foreach ($dhcpServer in $dhcpServers) {
Write-Host "Searching $dhcpServer..."
Get-DhcpServerv4Scope -ComputerName $dhcpServer | ForEach-Object {
$results += Get-DhcpServerv4Reservation -ComputerName $dhcpServer -ScopeId $_.ScopeId -ClientId $clientId -ErrorAction SilentlyContinue
}
$results | ForEach-Object {$_ | Add-Member -membertype noteproperty -Name Server -Value $dhcpServer -ErrorAction SilentlyContinue}
}
Write-Output $results | select Server, IPAddress, ScopeId, ClientId, Name, Description | ft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment