I am trying to filter the results of running the netsh command to retrieve a certain value.
PS C:\windows\system32> netsh interface ipv4 show interfaces
Idx Met MTU State Name
--- ---------- ---------- ------------ ---------------------------
1 50 4294967295 connected Loopback Pseudo-Interface 1
12 25 1500 connected Wireless Network Connection
11 10 1500 connected Local Area Connection
14 40 1500 disconnected Bluetooth Network Connection
21 20 1500 connected VMware Network Adapter VMnet1
22 20 1500 connected VMware Network Adapter VMnet8
I want to retrieve the Idx value of the Local Area Connection.
Piping the above netsh command to Where-Object doesnt seem to work.
Assign a variable to the netsh command above to treat it as an object doesnt seem to work either.
How can I achieve this?
Thanks!
Based on below answers and playing around this is the solution I came up with, not pretty, but it works. I have to wonder if there is a .NET equivalent that I can use, but Ill save that for a later date. Thanks for the help.
$interfaces = netsh interface ipv4 show interfaces
foreach ($i in $interfaces)
{
if ($i -match 'Local Area Connection') {
$indexvalue = $i.Substring(0,6)
$indexvalue = $indexvalue.Trim()
Write-Host $indexvalue
}
}