A question on the forum asked about discovering those network adapters that had IP addresses configured. The user had tried
PS> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPAddress IS NOT NULL”
Get-WmiObject : Invalid query “select * from Win32_NetworkAdapterConfiguration where IPAddress IS NOT NULL”
At line:1 char:1
+ Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPAdd …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Actually they’d tried the full WQL query. I don’t do that because its more typing than using the class name and a filter.
The problem is that IPAddress is a string array and WQL won’t let you query against an array of properties.
You have 2 choices
Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where IPAddress
which is fine fro local machines but means you are filtering out results on the local machine when querying a remote machine – wasteful.
A better solution is to use the IPEnabled property. This is a boolean that is set to TRUE when an IP address (static or DHCP) has been set on a NIC. Your query then becomes
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPEnabled = $true”
OR
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “IPEnabled = $true”