DHCP Roll Call
Scriptable method for obtaining a list of DHCP server names in a domain.
- By Bill Boswell
Do you know an easy way of getting a list of DHCP
servers for the current domain? NETSH gives me all the servers in the
forest, which, in my organization, runs into the hundreds. I have tried
dsget and dsquery too:
dsquery * -Filter (objectclass=dhcpclass) -attr dhcpserver
and have tried scripting the LDAP queries, without success. What am I
—Alan M. Kaplan, MCSE
Alan: It turns out to be something of a trick to do this
search. Active Directory stores the DHCP server information in a series
of DHCPClass objects in this container:
The browse tool in the DHCP console simply enumerates the objects in
this container and displays the content of an attribute called "dhcpservers"
— note the "s" at the end of the attribute name. Your dsquery
statement would have done the same but it has a couple of syntax errors.
Here is a corrected expression:
dsquery * forestroot -filter (objectclass=dhcpclass) -attr
Help from Bill
Got a Windows or Exchange question or need troubleshooting
help? Or maybe you want a better explanation than provided
in the manuals? Describe your dilemma in an e-mail
to Bill at mailto:email@example.com;
the best questions get answered in this column.
When you send your questions, please include your
full first and last name, location, certifications (if
any) with your message. (If you prefer to remain anonymous,
specify this in your message but submit the requested
information for verification purposes.)
Unfortunately, as you'll see when you try the expression, the dhcpservers
attribute doesn't appear in the list of attributes for the DHCPClass objects.
That's because the dhcpservers attribute uses an IA5-String syntax (also
called "printable string") which, apparently, dsquery can't
process. You can view the content of the dhcpservers attribute using ADSIEdit
or ldp. The attribute contains a concatenated set of values in this format:
An actual entry for a server named W2K3-S5 in the domain Exorg.com with
the IP address 10.0.0.133 looks like this:
Readers: I proceeded to send Alan a simple few lines of
script, which he tried with mixed results. The dhcpservers attribute can
have a variety of formats that require special handling. Alan responded
with a rework of the script that included a great deal more error checking,
a nice set of functions for doing the report formatting and a section
for saving the output to a file. Here is a link to Alan's code:
which I'm including with his permission. Thanks, Alan!
As with any script you download from the Internet, you should test it
thoroughly in a lab environment before using it in production. (And if
you have trouble downloading the script, write to Michael Domingo, Editor,
MCPmag.com at firstname.lastname@example.org
to get it e-mailed to you.)
Contributing Editor Bill Boswell, MCSE, is the principal of Bill Boswell Consulting, Inc. He's the author of Inside Windows Server 2003 and Learning Exchange Server 2003 both from Addison Wesley. Bill is also Redmond magazine's "Windows Insider" columnist and a speaker at MCP Magazine's TechMentor Conferences.