问题
I can use the following WMI query to determine any DNS servers my machine might be using:
SELECT DNSServerSearchOrder
FROM Win32_NetworkAdapterConfiguration
However, the following query I wrote to ignore null entries is invalid and I don't know why:
SELECT DNSServerSearchOrder
FROM Win32_NetworkAdapterConfiguration
WHERE DNSServerSearchOrder!=null
Is there a way to filter out the null entries?
回答1:
The WQL language supports !=
and the IS [NOT] NULL
syntax, the problem is the property which you choose DNSServerSearchOrder
is an array, and you can't use an array property in a WQL Where sentence. So the workaround is use another property of the Win32_NetworkAdapterConfiguration WMI class in the where condition.
回答2:
Just use this
WHERE IPEnabled=True
回答3:
This is an older post, but I needed this information myself today, from Powershell to list out the IP addresses used as DNS servers on a system:
Get-WmiObject -Namespace root\cimv2 -Query "Select dnsserversearchorder from win32_networkadapterconfiguration" | where {$_.DNSServerSEarchOrder -ne $null} | select -ExpandProperty DNSServerSearchOrder
This results in a simple array of the IP addresses which can be used further in Powershell, either by sending to a variable or by piping through to another command.
回答4:
Are you looking for this instead:
SELECT DNSServerSearchOrder
FROM Win32_NetworkAdapterConfiguration
WHERE DNSServerSearchOrder IS NOT NULL
来源:https://stackoverflow.com/questions/16804412/wmi-query-to-determine-dns-servers-without-null-entries