任何人都可以告诉我为什么这个命令有效:
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
我应该使用什么呢?
答案 0 :(得分:1)
MacAddress是一个字符串,IPAddress是一个字符串Array。
MSDN doc for Win32_NetworkAdapterConfiguration class
基本上,您只需要获取所有适配器并解析IPAddress是否有效,因为NULL和Empty是无效查询。