【问题标题】:Get-WMIObject: why does != NULL work with MACAddress but not IPAddress?Get-WMIObject:为什么 != NULL 适用于 MAC 地址而不适用于 IP 地址?
【发布时间】:2013-10-29 05:59:34
【问题描述】:

谁能告诉我为什么这个命令有效:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "MACAddress != NULL"

而这个:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPAddress != NULL"

产生:

Get-WmiObject : Invalid query "select * from Win32_NetworkAdapterConfiguration where IPAddress != NULL"
At line:1 char:1
+ Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPAddress != NUL ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

我应该使用什么?

【问题讨论】:

    标签: powershell wmi


    【解决方案1】:

    MacAddress 是一个字符串,IPAddress 是一个字符串数组。

    MSDN doc for Win32_NetworkAdapterConfiguration class

    基本上,您只需要获取所有适配器并解析 IPAddress 是否有效,因为 NULL 和 Empty 是无效查询。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 2016-09-07
      • 1970-01-01
      • 2022-07-11
      • 2021-09-28
      相关资源
      最近更新 更多