我试着做这样的事情:
Get-WmiObject Win32_NetworkAdapterConfiguration `
-Filter "DefaultIPGateway!=NULL"但我有个错误:
一行的无效查询:1 char:14 + Get-WmiObject <<<< Win32_NetworkAdapterConfiguration -Filter "DefaultIPGateway!=NULL“+ CategoryInfo : InvalidOperation:(:) Get-WmiObject,ManagementException + FullyQualifiedErrorId : GetWMIManagementException,CategoryInfo
这很奇怪,因为当我尝试获取DefaultIPGateway值的类型时。它是现有值的System.Array:
PS> $result[0].DefaultIPGateway.Gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String[] System.Array对于不存在的值,为NULL:
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有人能帮助我理解为什么我的WQL不起作用,以及我该怎么做才能让它运转起来?
发布于 2015-02-13 15:07:06
我不知道如何使筛选器查询工作,因为我不知道如何访问数组元素来检查它们,但有一个解决办法:
Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIPGateway -ne $null }这样,powershell将负责过滤从查询返回的对象,而不是在检索期间进行WMI。
发布于 2016-01-31 11:20:32
WQL-查询不支持数组属性。
注WQL不支持数组数据类型的查询。
解决方案是使用PowerShell的Where-Object cmdlet过滤空值对象。
Get-WmiObject -Class Win32_NetworkAdapterConfiguration |
Where-Object { $_.DefaultIPGateway }https://stackoverflow.com/questions/28502337
复制相似问题