Powershell One-Liner to Search DHCP for a IP address of a MAC Address

So, I recently had a need to quickly and easily search a considerably large amount of DHCP Pools for some Polycom Trio devices. and James Cussens VVX manager returned too many results to find what I was looking for (well, until I hacked it to support Trio’s)

Bascially, feed it a MAC and it will return the IP if the DHCP server has leased it.

Figured someone else would find this handy. Run this from a host with the DHCP tools installed. it will poll the local machine by default, but you can just update the machine name and mac address as required.

Get-DhcpServerv4Scope | foreach {Get-DhcpServerv4Lease -computername $env:computername -allleases -ScopeId ($_.ScopeId) as [string] } | ? clientid -match '00-04-f2-f' 

Enjoy.

 

4 thoughts on “Powershell One-Liner to Search DHCP for a IP address of a MAC Address

      1. Tim Olvera

        You have to remove ‘as [string]’ and your command works.

        Get-DhcpServerv4Scope | foreach {Get-DhcpServerv4Lease -computername $env:computername -allleases -ScopeId ($_.ScopeId)} | ? clientid -match ’00-04-f2-f’

        Reply

Leave a Reply

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.