WQL in the filter does not work

I am trying to do something like:

Get-WmiObject Win32_NetworkAdapterConfiguration `
    -Filter "DefaultIPGateway!=NULL"

But I have an error:

Get-WmiObject: invalid request On the line: 1 char: 14 + Get-WmiObject <<Win32_NetworkAdapterConfiguration -Filter "DefaultIPGateway! = NULL" + CategoryInfo: InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId: GetWMIMan. PowerShell.Commands.GetWmiObjectCommand

This is strange because when I try to get the value type of DefaultIPGateway. This is System.Array for existing values:

PS> $result[0].DefaultIPGateway.Gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String[]                                 System.Array

And NULL for nonexistent values:

PS> $result[1].DefaultIPGateway.GetType()
You cannot call a method on a null-valued expression.
At line:1 char:36
+ $result[1].DefaultIPGateway.GetType <<<< ()
    + CategoryInfo          : InvalidOperation: (GetType:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Can someone help me understand why my WQL is not working and what should I do to get it gone?

+4
source share
2

, , , , , :

Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIPGateway -ne $null }

, powershell , , WMI, .

+2

WQL- .

. WQL .

: WQL @MSDN

, PowerShell Where-Object.

Get-WmiObject -Class Win32_NetworkAdapterConfiguration |
Where-Object { $_.DefaultIPGateway }
+1

All Articles