Home > Mobile >  GWMI Win32_NetworkAdapterConfiguration - Display Description and IP Address but only IPV4 (Exclude I
GWMI Win32_NetworkAdapterConfiguration - Display Description and IP Address but only IPV4 (Exclude I

Time:11-21

relatively new to Powershell.

I'm trying to output the Description and IPAddress values from the following code, without it outputing the IPV6 addresses with it.

I want the Description and the IPAddress values, I've managed to get it to output just IPV4 by doing Select -Expand IPAddress and a Like command, but I want the description to, when I try to add Description via select it just breaks the entire thing.

Below is as close as I've come, shows me Description IP Address, but I want to hide the IPV6 to keep it neat.

gwmi Win32_NetworkAdapterConfiguration -computername $endpointip |
             Where { $_.IPAddress -notlike '*::*'  } | Where {$_.Description -like '*GbE*' -or $_.Description -like '*Ethernet*' -or $_.Description -like '*Wi-Fi*'-or $_.Description -like '*Wireless*' -or $_.Description -like '*Cisco*'}| # filter the objects where an address actually exists
                             Select Description, IPAddress| Out-String # retrieve only the property *value*

Also tried it

$_.IPAddress -like '*.*.*'

However that just outputs like the below, I don't want the IPV6 Addresses

`Description                                                                      IPAddress                                                          
-----------                                                                      ---------                                                          
Intel(R) Wireless-AC 9560 160MHz                                                 {192.168.0.16, fe80::50d0:fda6:44ee:237d}                          
Realtek PCIe GbE Family Controller                                                                                                                  
Microsoft Wi-Fi Direct Virtual Adapter                                                                                                              
Microsoft Wi-Fi Direct Virtual Adapter                                                                                                              
Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64 {x.x.x.x, xxxx::xxxx:xxxxx:xxxx, xxxx::xxxx:xxxx:xxxx:xxxx}
Realtek USB GbE Family Controller `

Or like this

Description                                                                      IPAddress                                                          
-----------                                                                      ---------                                                          
Intel(R) Wireless-AC 9560 160MHz                                                 {192.168.0.16, fe80::50d0:fda6:44ee:237d}                          
Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64 {xx.xx.xx.xx, xxxx::xxxx:xxxxx:xxxx, xxxx::xxxx:xxxx:xxxx:xxxx}

Any help would be appreciated, thanks

CodePudding user response:

What you're trying to filter by is working as it's suppose to, in regard to how PowerShell "thinks". *.*.* will get the objects that have a value in IPAddress matching *.*.*, but it's not excluding the other values. The immediate fix would be using a calculated property to extract that IP address:

gwmi Win32_NetworkAdapterConfiguration -computername $endpointip | 
    Where {$_.Description -like '*GbE*' -or $_.Description -like '*Ethernet*' -or $_.Description -like '*Wi-Fi*'-or $_.Description -like '*Wireless*' -or $_.Description -like '*Cisco*'} | 
    Select Description, @{
        Name = 'IPAddress'
        Expression = { $_.IPAddress | Select -First 1}
    }

Here, you tell it to select just the first object value in IPAddress which is almost always the IPv4 Address.

  • You can also use a filter against it to ensure that IP Address is matched using $_.IPAddress | ? { $_ -like '*.*' } instead.

Without knowing your PS version, Get-CimInstance superseded Get-WMIObject as of PS 3.0 where it's not supported in PS core either.

  • Related