Help in understanding a line of code

This topic contains 3 replies, has 2 voices, and was last updated by  Don Jones 5 months ago.

  • Author
    Posts
  • #70652

    sahar
    Participant

    $arp = arp -a | Where {$_ -and $_ -notmatch 'internet address\s+physical address\s+type'}

    What i dont get here is the "$_ -and $_ " part.
    i get that this gets the output of arp -a and then brings back everything except the phrase in the regex.
    i know the $_ is the piped data but i still dont understand that condition, help?

  • #70654

    Don Jones
    Keymaster

    That's not a really well-written Where clause, honestly.

    It's saying, "where $_ contains something, and where $_ does not match the following regular expression."

    I'd prefer:

    $_ -ne $null -and $_ -notmatch 'internet address\s+physical address\s+type'
    

    Or something a little more declarative.

    • #70658

      sahar
      Participant

      Thanks for the fast response i think ill implement it your way since it is more informative, can i use the PSItem instead of the $_? or it may cause some compatibility issues with other PS vers?

  • #70663

    Don Jones
    Keymaster

    $PSItem was introduced in v3.

You must be logged in to reply to this topic.