asked on
Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration
Wich will give me multiple unneeded adapters. So I'd like to filter these on the ones which have at least one addresses.Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null }
And now I've got it mostly correct but I have entries like that:DHCPEnabled : True
IPAddress : {169.254.19.108, fe80::30e7:9436:7ca:136c}
DefaultIPGateway :
DNSDomain :
ServiceName : VMSMP
Description : Hyper-V Virtual Ethernet Adapter
Index : 5
DHCPEnabled : True
IPAddress : {11.11.11.11, fe80::4889:c466:5428:5068}
DefaultIPGateway : {11.11.11.3}
DNSDomain : company.cc
ServiceName : VMSMP
Description : Hyper-V-Adapter - virtuelles Ethernet #2
Index : 6
So I'd like to filter the unwanted 169 configured adapter. Because with this way I think I'm able to find and list all valid configured adapters (LAN, Wifi, USB Connected Adapter) in different networks 11.11.11.0/24 or 192.168.0.0/24:Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -notlike "*169.254*" }
But this doesn't work, because notlike seems not working on an array.
ASKER
$_.IPAddress -notlike "*169.254*"
does not filter, because its in array.PS C:\WINDOWS\system32> Get-WmiObject -ComputerName $computer -Class Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -notlike "*169.254*" -and $_.IPAddress -ne $null}
DHCPEnabled : True
IPAddress : {169.254.19.108, fe80::30e7:9436:7ca:136c}
DefaultIPGateway :
DNSDomain :
ServiceName : VMSMP
Description : Hyper-V Virtual Ethernet Adapter
Index : 5
DHCPEnabled : True
IPAddress : {11.11.11.11, fe80::4889:c466:5428:5068}
DefaultIPGateway : {11.11.11.3}
DNSDomain : company.cc
ServiceName : VMSMP
Description : Hyper-V-Adapter - virtuelles Ethernet #2
Index : 6
Get-WmiObject -ComputerName $computer -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled='TRUE'" | Where-Object {
$_.IPAddress | Where-Object { $_ -notlike "*169.254*" }
}
The filter I've added should take care of interfaces which have no IP addresses.
ASKER
Get-WmiObject -ComputerName localhost -Class Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null -and $_.IPAddress[0] -notlike "*169*" }
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.
TRUSTED BY
Open in new window