DHCP Roll Call

Scriptable method for obtaining a list of DHCP server names in a domain.

Bill: 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 cn

and have tried scripting the LDAP queries, without success. What am I missing?
—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:

cn=NetServices,cn=Services,cn=Configuration,dc=<domain>,
dc=<root>

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 *

Get 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:boswell@101com.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:

i<ip_address>$rcn=<common_name>$f<flags>$s<server_FQDN>$;

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:

i10.0.0.133$rcn=10.0.0.133$f0x00000000$sW2K3-S5.exorg.com$

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:

http://mcpmag.com/downloads/2004/searchdhcpbydomain.txt

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 mdomingo@101com.com to get it e-mailed to you.)

About the Author

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.

Featured

  • Microsoft Offers More Help on Windows Server 2008 Upgrades

    Microsoft this week published additional help resources for organizations stuck on Windows Server 2008, which fell out of support on Jan. 14.

  • Microsoft Ups Its Carbon Reduction Goals

    Microsoft on Thursday announced a corporatewide carbon reduction effort that aims to make the company "carbon negative" by 2030.

  • How To Dynamically Lock Down an Unattended Windows 10 PC

    One of the biggest security risks in any organization happens when a user walks away from their PC without logging out. Microsoft has the solution (and it's not a password-protected screensaver).

  • First Stable Chromium-Based Microsoft Edge Browser Released

    Microsoft on Wednesday announced the first release of its Chromium-based Microsoft Edge browser at the "stable" commercial-release stage.

comments powered by Disqus

Office 365 Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.