Can you use WMI to determine if a connection gets its DNS servers from DHCP?

Usually if a client is getting an IP from DHCP, it obtains DNS servers as well...usually.

But for your request for WMI, I don't think so.

For DNS you have these Properties:

------------------------------------ ---------- -------------------------
 Class Name                           Type       Property Name
------------------------------------ ---------- -------------------------
 Win32_ComputerSystem                 String     DNSHostName
 Win32_NetworkAdapterConfiguration    String     DNSDomain
 Win32_NetworkAdapterConfiguration    String     DNSDomainSuffixSearchOrder
 Win32_NetworkAdapterConfiguration    Boolean    DNSEnabledForWINSResolution
 Win32_NetworkAdapterConfiguration    String     DNSHostName
 Win32_NetworkAdapterConfiguration    String     DNSServerSearchOrder
 Win32_NetworkAdapterConfiguration    Boolean    DomainDNSRegistrationEnabled
 Win32_NetworkAdapterConfiguration    Boolean    FullDNSRegistrationEnabled
 Win32_NTDomain                       String     DnsForestName
 Win32_NTDomain                       Boolean    DSDnsControllerFlag
 Win32_NTDomain                       Boolean    DSDnsDomainFlag
 Win32_NTDomain                       Boolean    DSDnsForestFlag
------------------------------------ ---------- -------------------------

For DHCP you have:

------------------------------------ ---------- -------------------------
 Class Name                           Type       Property Name
------------------------------------ ---------- -------------------------
 Win32_NetworkAdapterConfiguration    Boolean    DHCPEnabled
 Win32_NetworkAdapterConfiguration    DateTime   DHCPLeaseExpires
 Win32_NetworkAdapterConfiguration    DateTime   DHCPLeaseObtained
 Win32_NetworkAdapterConfiguration    String     DHCPServer
------------------------------------ ---------- -------------------------

Out of those above...none specifically shows anything to tell you it is getting DNS servers from DHCP. DNSServerSearchOrder will list the servers in an array, but won't say "I got these from the DHCP Server.

EDIT: however, all that said about WMI, one way I do see is to use the old netsh command.

Specifically:

netsh interface ipv4 show dns

notice there will be a line called: "DNS servers configured through DHCP" if they are configured that way.


Run Get-WMIObject Win32_NetworkAdapterConfiguration on the system and you will see the first property output is:

DHCPEnabled:True

Unfortunately, that is the closest you are going to get to DHCP information and obviously it doesn't specify DNS info. From Microsofts documentation, the WMI object Win32_NEtworkAdapterConfiguration does not hold that setting.

http://msdn.microsoft.com/en-us/library/aa394217%28v=vs.85%29.aspx