powershell - WMI parsing not expected result -
i wrote script ip address of remote machine, working intended. problem i'm trying show ipv4 address , not ipv6 address created logic not working, doing wrong here?
get-wmiobject -computername remoteserver win32_networkadapterconfiguration | ? { $_.ipaddress -ne $null -and $_.ipaddress -ne 'fe80*' } | select -expandproperty ipaddress
looking @ below, can see ipaddress
property of win32_networkadapterconfiguration
object, it's object array:
dhcpenabled : false ipaddress : {192.168.3.1, fe80::8c4a:cfd3:6c30:5695} defaultipgateway : dnsdomain : servicename : vmnetadapter description : vmware virtual ethernet adapter vmnet1 index : 5 ps> ((get-wmiobject win32_networkadapterconfiguration | select ipaddress ).ipaddress).gettype() ispublic isserial name basetype -------- -------- ---- -------- true true object[] system.array
this means need iterate on array foreach %
extract value want:
get-wmiobject win32_networkadapterconfiguration | ? { $_.ipaddress -ne $null} | % { $_.ipaddress -inotlike 'fe80*' }
also note i've changed comparison -ne
-inotlike
. -ne
matches exactly, whereas can use wildcard *
in -like
comparison
Comments
Post a Comment