문제

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
    }
}
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top