How to strip out everything but numbers in a variable?

Viewed 534

I'm trying to automate setting an IP address through PowerShell and I need to find out what my interfaceindex number is.

What I have worked out is this:

$x = ( Get-NetAdapter |
       Select-Object -Property InterfceName,InterfaceIndex |
       Select-Object -First 1 |
       Select-Object -Property Interfaceindex ) | Out-String

This will output:

InterfaceIndex
--------------
             3

Now the problem, when I try to grab only the number using:

$x.Trim.( '[^0-9]' )

it still leave the "InterfaceIndex" and the underscores. This causes the next part of my script to error because I just need the number.

Any suggestions?

3 Answers
Related