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?
GeologyETHAsked:
Who is Participating?
 
Dusan_BajicConnect With a Mentor Commented:
just add option 1 at the end
...... show clients 1 >> leases.txt)
0
 
KenMcFCommented:
You can use netsh dhcp server

netsh dhcp server dump

netsh dhcp server show all

then parse the output to the way you want.
0
[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.

 
ipajonesCommented:
Try this in your script:

netsh dhcp server \\dhcpservername show scope scope_name show clients

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

From novice to tech pro — start learning today.