The operator is -or
, not or
. See about_Logical_Operators
. Also, if
statements don’t read from the pipeline. Either put the if
statement in a ForEach-Object
loop:
... | ForEach-Object { if ($_.extensionattribute9 -eq 'Smith, Joe' -or $_.extensionattribute9 -eq 'Doe, John') { $_ | select extensionsattribute9, country } }
or use a Where-Object
statement instead:
... | Where-Object { $_.extensionattribute9 -eq 'Smith, Joe' -or $_.extensionattribute9 -eq 'Doe, John' } | Select-Object extensionsattribute9, country
And you can’t use property names by themselves. Use the current object variable ($_
) to access properties of the current object.
For checking if an attribute has one of a given number of values you can also use the -contains
operator instead of doing multiple comparisons:
'Smith, Joe', 'Doe, John' -contains $_.extensionattribute9