...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


Site Updates

Querying DHCP with PowerShell for a specific IP

Monday, October 28, 2013 in Powershell (Views: 1754)
A quickie, for those who need an IP address for a computer, but DNS hasn't updated yet. You can use PowerShell to accomplsh this task by querying DHCP directly. How? The Get-DhcpServerv4Lease cmdlet.

Here is a quick and easy command you can use to enumerate your DHCP server. In my case, the client name is CLIENT1 and the DHCP Server is DHCPServer1.

Get-DhcpServerv4Lease -ComputerName DHCPServer1 -AllLeases -ScopeId

But how to find the Scope ID? Worry no more. Use this cmdlet, if you don't know the Scope ID by memory.

Get-DhcpServerv4Scope -cn DHCPServer1

And lastly, what about that specific machine? Well, you can expand upon the previous query.

Get-DhcpServerv4Lease -ComputerName DHCPServer1 -AllLeases -ScopeId | ? hostname -match 'CLIENT1'

Happy scripting.


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.