Question

I am using gwmi to return a lot of different information on a system. I used the following command to get the network information:

$networkInfo = gwmi win32_networkadapterconfiguration 

which returns an array of network adapters and information on them. Since there are a number of network adapters that I am not intersted in, how do I filter out the "bad" ones? I would guess I need to get just the ones with an IPv4 address, but how do I specify that?

Do I have to use an if nested in a for loop, or is there a quicker way?

psuedo code:

for ($i=0; $i -lt $networkInfo[$i].length; $i++){
    if($networkInfo[$i].IPAddress has a value){
        #do stuff
    }
}
Was it helpful?

Solution

As was mentioned in the comments, you can use the Where-Object command to filter result in the pipeline. For your specific needs this should work:

gwmi win32_networkadapterconfiguration | where IPAddress -NE $NULL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top