Skip to main content

Search DHCP for a MAC Address with Powershell

·198 words·1 min
system-administration tech dhcp powershell sysadmin technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure

Many many moons ago, we had a way to trawl through DHCP scopes utilising the netsh tool to find devices on our networks that match a certain MAC address.

Instead of relying on such an outdated tool that isn’t on Microsoft’s radar to keep alive, I’ve cobbled together a function in Powershell aptly named Get-Mac to perform some duty which added functionality (and no required to log onto DHCP hosts).

The above function will by default, utilise the Get-DhcpServerInDC to return all your DHCP servers, obtain all their scopes with Get-DhcpServerv4Scope, look through each scopes lease with Get-DhcpServerv4Lease and finally match any lease with the MAC address provided. If you have a large enterprise network, comprises of multiple AD sites, then you can narrow the field down with the -DhcpSite together with the DNS name of your DHCP server in that site. Both the -Mac and the -DhcpSite switches work on wildcard matches so you won’t need the full address or full name of the DHCP server. Hopefully your AD sites have a naming convention which should assist narrowing it down.

Let me know if you found this one useful in your SysAdmin’ing day or think of improvements.

Related

Legacy BIOS and UEFI PXE coexistence
·701 words·4 mins
system-administration tech bios dhcp powershell pxe sccm sysadmin technology uefi windows-server-2012-r2
More and more enterprises are moving towards the modern UEFI devices in their fleet, whether that be desktops, laptops or convertibles.
Using Powershell and WMI to get the MAC address of Remote workstation
·306 words·2 mins
system-administration tech gwmi powershell sysadmin technology wmi
It has cropped up from time to time that we need to retrieve information, in this example, the MAC address from remotely located workstations.
How to restore a tree of objects from the Active Directory Recycle Bin
·710 words·4 mins
system-administration tech active-directory powershell sysadmin technology
In a previous post I detailed how to setup the Active Directory Recycle Bin and restore single deleted objects back in your Active Directory.