Reputation: 709
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?
Upvotes: 6
Views: 19126
Reputation: 6978
In PowerShell v3+:
Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Select-Object -ExpandProperty DNSServerSearchOrder
Due to the way -ExpandProperty
works, null (missing) entries will be omitted incidentally.
Upvotes: 0
Reputation: 21
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.
Upvotes: 1
Reputation: 136431
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.
Upvotes: 8
Reputation: 62861
Are you looking for this instead:
SELECT DNSServerSearchOrder
FROM Win32_NetworkAdapterConfiguration
WHERE DNSServerSearchOrder IS NOT NULL
Upvotes: -1