locked
Get-NetConnectionProfile piped to show results based on 2 of the values? RRS feed

  • Question

  • Hi all

    Get-NetConnectionProfile

    This lists multiple connections.

    What command can I use to give me the results for just the below connection ie 

    if the InterfaceAlias is "Tunnel" and the Name is "mydomain.uk"   ?

    Name : mydomain.uk
    InterfaceAlias : Tunnel
    InterfaceIndex : 87
    NetworkCategory : DomainAuthenticated
    IPv4Connectivity : Internet
    IPv6Connectivity : NoTraffic

    I've tried a piped where -match - like -eq, I'm getting the syntax wrong somewhere.

    Thanks for any info.

    Thursday, June 4, 2020 4:47 PM

Answers

  • This should do it:

      Get-NetConnectionProfile | where-object {$_.InterfaceAlias -eq 'Tunnel' -and $_.Name -eq 'mydomain.uk'}


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by ancient3333 Friday, June 5, 2020 10:02 PM
    Thursday, June 4, 2020 9:22 PM

All replies

  • I would suggest that you read the help for the CmdLet as it answers your question directly.

    Get-NetConnectionProfile -name mydomain.uk


    \_(ツ)_/

    • Proposed as answer by Vector BCO Thursday, June 4, 2020 8:57 PM
    Thursday, June 4, 2020 5:11 PM
  • The help does not help with the 2nd requirement.

    I need it to show me the InterfaceAlias ...IF name is mydomain.uk

    This is so later I can invoke a : do until "InterfaceAlias = Tunnel...AND name =mydomain.uk"

    Thursday, June 4, 2020 9:06 PM
  • This should do it:

      Get-NetConnectionProfile | where-object {$_.InterfaceAlias -eq 'Tunnel' -and $_.Name -eq 'mydomain.uk'}


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by ancient3333 Friday, June 5, 2020 10:02 PM
    Thursday, June 4, 2020 9:22 PM
  • I wouldn't use a "Do {…} Until (<condition>)" unless you're very sure that the <condition> will, at some point, be satisfied. If it isn't, you'll loop forever!

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, June 4, 2020 9:26 PM
  • Thank you Rich...perfect.

    I noticed it still works with...just " | where   "

    What is the relevance of -object ?

    I hear you on the do condition, it does indeed complete eventually.

    Cheers.

    Friday, June 5, 2020 10:06 PM
  • "Where" is shorthand (an alias) for "Where-Object", just like "Select" is for "Select-Object". But be careful of "ForEach-Object" and "ForEach" because depending on how/where you use them "ForEach" can interpreted as either a keyword or a cmdlet.

    https://stackoverflow.com/questions/29148462/difference-between-foreach-and-foreach-object-in-powershell

    The "Do" loop may complete in your situation today, but if I were you I wouldn't be my paycheck on it completing every time!


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Saturday, June 6, 2020 2:09 AM