Avatar of Lionstone
Lionstone

asked on 

Powershell - NetworkInfos - Expanded Properties Filter

With powershell at the end I'd like to have a value like
Adapter, IPv4Address, MAC Address

I've got know the idea to get that with:
Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration

Open in new window

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 }

Open in new window

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

Open in new window

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*" }

Open in new window

But this doesn't work, because notlike seems not working on an array.
Powershell

Avatar of undefined
Last Comment
oBdA
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

This might work for you:

Get-WmiObject -ComputerName $computer -Class Win32_NetworkAdapterConfiguration | Where-Object {$_.IPAddress -notlike "*169.254*" -and $_.IPAddress -ne $null}

Open in new window

Avatar of Lionstone
Lionstone

ASKER

nope.. sorry... forgot to mention
Exactly the filter
$_.IPAddress -notlike "*169.254*"

Open in new window

does not filter, because its in array.

so your powershell
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

Open in new window

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

You can nest Where-Object statements. It's a bit mucky, but it gives you the wildcard comparison on the array content.
Get-WmiObject -ComputerName $computer -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled='TRUE'" | Where-Object {
    $_.IPAddress | Where-Object { $_ -notlike "*169.254*" }
}

Open in new window

The filter I've added should take care of interfaces which have no IP addresses.
Avatar of Lionstone
Lionstone

ASKER

this seems not working for me..

at the moment I'll try with that:
Get-WmiObject -ComputerName localhost -Class Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null -and $_.IPAddress[0] -notlike "*169*" }

Open in new window

SOLUTION
Avatar of Lionstone
Lionstone

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Powershell
Powershell

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.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo