WQL Invalid Query for NetworkAdapterConfiguration


I’m trying to get all the instances from Win32_NetworkAdapterConfiguration where the IPAddress is greater than NULL.

I’m running this Cmdlet but the result says “Invalid Query”:

Get-CimInstance -Query " Select * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress IS NOT NULL"

OR this one:

Get-WmiObject -Query " Select * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress  'NULL'"

I’ve tried the same syntax on a different class and got results:

Get-ciminstance -Query " Select * FROM Win32_NetworkAdapter WHERE AdapterType IS NOT NULL"

I can work around my problem by doing this:

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration | ? {$_.IPAddress -gt $null}

Anyone got a clue to why this doesn’t work?

Some properties do work for the NetworkAdapterConfiguration class. e.g IPXAddress

Looking more closely, the properties that can’t be queried are stored as an array of values. Properties that can be queried are not stored as an array (note the absence of square brackets).

#Output from Get-Member
IPAddress                  Property      string[] IPAddress {get;set;}
IPXAddress                 Property      string IPXAddress {get;set;}

According to this document, WQL does not support querying of array datatypes.

To workaround this, you’ll need to pipe to Where-Object.

Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -ne $NULL} | Select-Object *

Rather than using the IPAddress property use the IPEnabled property. This is a simple boolean that’s set when an IP address (static or DHCP) is set on a NIC.

Your query becomes
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPEnabled = $true”

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “IPEnabled = $true”

Thank you guys for some great answers!

I’ll work around this with where-object or with the IPEnabled property…
At least next time I won’t get stuck on that again!