WMI Query to determine DNS Servers without null entries

十年热恋 提交于 2021-01-27 06:39:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!