information from Windows dhcp

I need to fetch the current leases from a Windows dhcp server by a script. Or is a kind of dhcp query possible?
Who is Participating?
Dusan_BajicConnect With a Mentor Commented:
just add option 1 at the end
...... show clients 1 >> leases.txt)
You can use netsh dhcp server

netsh dhcp server dump

netsh dhcp server show all

then parse the output to the way you want.
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Try this in your script:

netsh dhcp server \\dhcpservername show scope scope_name show clients

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)
GeologyETHAuthor Commented:
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.
GeologyETHAuthor Commented:
The scripts works, but doesn't deliver the client's name + ip-no. Any other idea?
All Courses

From novice to tech pro — start learning today.