Where-object $_ matches multiple criterias

powershell

Solution

This should do what you want, and is a bit shorter than what you originally had.

$data | Where-Object{
  $_.Name -eq "$serverName.chrobinson.com" -and (
     $_.Description1 -match "bnx2x" -or
     $_.Description1 -match "be2net"
  )
} | Select-Object -expand version

You just needed `$_.Description1 -match "bnx2x" -or $_.Description1 -match "be2net"` really, but I think this is easier to read than what you had.

Problem

``` $data|where-object{$_.Name -eq "$serverName.domain.com"}|select-object -Property Description1, Version | where-object{$_.Description1 -match "bnx2x" -or "be2net"} | %{"{0}" -f $_.Version} ``` So I'm trying to get the version number. However, the Description1 can have two names that I want to look for. I've gotten my code to work for just matching one string but I cant seem to find the right syntax to match multiple strings with an "-or"

Original source