kamokoba
kamokoba

Reputation: 597

PowerShell: defining multiple conditions in Where-Object

I have a sample array and I try to create a rule which will filter our either of the 2 items that are present in the array.

Sample array:

$d_c_arr = @('idata', 'quanthouse', 'reuters', 'bloomberg', 'fidelity', 'nasdaq')

The items that I want to filter out are 'idata' and 'quanthouse'.

The filtering rule should adapt to the situations where either both 'idata' and 'quanthouse' exist or only one of them is present in an array.

My attempt to define the rule:

$d_c_arr | Where-Object { $_ -notlike 'idata' -or $_ -notlike 'quanthouse' }

My expected output would be:

reuters
bloomberg
fidelity
nasdaq

However, the actual output is:

idata
quanthouse
reuters
bloomberg
fidelity
nasdaq

How to properly define the rule which would filter either of the 2 selected items in the array?

Upvotes: 0

Views: 1202

Answers (1)

sandthorn
sandthorn

Reputation: 2870

$d_c_arr | sls -pattern 'idata|quanthouse' -notmatch

[LIVE]

Your object are .net strings so can use select-string cmdlet.
select-string takes regex as its pattern.

Upvotes: 1

Related Questions