The DNS server search order for a network interface can be read from Win32_NetworkAdapterConfiguration like this in Powershell, or programmatically using .Net ManagementObjects:
> $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration | where{$_.IPEnabled -eq “TRUE”}
> $NICs[0]["DnsServerSearchOrder"]
192.168.1.1
192.168.1.2
The WMI property is set to the active DNS servers whether the interface is configured to get them from DHCP, or if they are set manually.
You can set them to fixed servers like this:
> $DNSServers = “198.102.234.125″,”198.102.234.126″
> $NIC.SetDNSServerSearchOrder($DNSServers)
To set an adapter to use DNS from a DHCP server, you call the set function with null as so:
> $NIC.SetDNSServerSearchOrder()
I was not able to find any distinctive traces of this setting in the registry.
Is there any way at all to tell that an interface is currently set to use DHCP to obtain its DNS servers?
Best Answer
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:
For DHCP you have:
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.