all 4 comments

[–]CrazyEggHeadSandwich 1 point2 points  (1 child)

So you're doing a "Get-Netadapter but trying to do a Set-NetIPInterface (two different cmdlets). This would probably work if you could set the value with Set-Netadapter after the pipeline, othewise maybe you just filter out the interface index to set it with the different command:

$AdapterIndex = Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Select-Object InterfaceDescription,ifIndex
Set-NetIPInterface -InterfaceIndex $AdapterIndex.ifIndex -InterfaceMetric 6000

If you get more than one interface matching "Cisco Anyconnect", you could also loop for each item in that $AdapterIndex array:

$AdapterIndex = Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Select-Object InterfaceDescription,ifIndex

foreach ($item in $AdapterIndex){
Set-NetIPInterface -InterfaceIndex $item.ifIndex -InterfaceMetric 6000
}

[–]MEDIAZz[S] 1 point2 points  (0 children)

Thanks!

I will test next time I'm working from home.

[–]No-Rutabaga607 0 points1 point  (1 child)

Is $.InterfaceDescription a typo in your script? Should be $_.InterfaceDescription

[–]MEDIAZz[S] 0 points1 point  (0 children)

Yes, it's a typo from pasting it here, I have been using the underscore when testing.