information from Windows dhcp

Posted on 2010-11-18
Last Modified: 2012-05-10
I need to fetch the current leases from a Windows dhcp server by a script. Or is a kind of dhcp query possible?
Question by:GeologyETH
LVL 27

Expert Comment

ID: 34164307
You can use netsh dhcp server

netsh dhcp server dump

netsh dhcp server show all

then parse the output to the way you want.
LVL 59

Expert Comment

by:Darius Ghassem
ID: 34164317

Expert Comment

ID: 34164335
Try this in your script:

netsh dhcp server \\dhcpservername show scope scope_name show clients

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


Expert Comment

ID: 34164876
What ipajones suggested will work, but if you have more than one scope you can run this as a .bat and get them all at once:

For /F "skip=5 delims= " %%a IN ('netsh dhcp server \\dhcpservername show scope') DO (
      if not %%a == Total (if not %%a == Command netsh dhcp server \\dhcpservername scope %%a show clients >> leases.txt)

Author Comment

ID: 34166660
Thanks for the answers. I tried "netsh server \\<server> scope x.y.z.c show clients", but this cmd doesn't include the client's name. I need the couple client's name + ip-no.
I modified the script dhcpcheckerv2.2 tow actual situation; it runs, but doesn't mail a result. Not sure what's wrong.

Author Comment

ID: 34173401
The scripts works, but doesn't deliver the client's name + ip-no. Any other idea?

Accepted Solution

Dusan_Bajic earned 500 total points
ID: 34173491
just add option 1 at the end
...... show clients 1 >> leases.txt)

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Event ID: 7023 / Source: Service Control Manager 4 114
Trasfering FSMO roles 8 100
Export DHCP scope Information 4 60
Enterprise Mode 4 28
Ever wondered why you had to use DHCP options (dhcp opt 60, 66 or 67) in order to use PXE? Well, you don't!
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question