I’d recommend to make a step back and start with learning the very basics of PowerShell first. This will save you from a lot of wasted time and frustrations.
Thanks for that, helped me get where I was headed.
$ifIndex = Get-NetAdapter -physical `
| where status -EQ -Value "Up" `
| Select-Object ifIndex `
; if($ifindex -Match".*(\d+)"){$matches.1}
Note: The use of single quotes within a code-block causes the code following to become italicised, causing the pipeline symbol to look like a forward-slash – another inline-code/code-block anomaly.
Another question, is the -Value flag strictly necessary in the above code; I’d have thought maybe just for integers?
get-help where-object -examples
--------------- Example 1: Get stopped services ---------------
Get-Service | Where-Object {$_.Status -eq "Stopped"}
Get-Service | where Status -eq "Stopped"
-------- Example 4: Use the comparison statement format --------
Get-Process | Where-Object -Property Handles -GE -Value 1000
Get-Process | where Handles -GE 1000
I usually do not care that much about the little awkwardnesses of the forum software and how it’s formatting the code. Much more important I think is NOT to use backticks as line continuation characters as it is considered very bad style and can cause hard to find errors.
PowerShell is very forgiving when it comes to code formatting and style. At the end of the day does the result count. But I try to follow most of the best practice and style guide recommendations anyway to make my code easy to read and consistent.