1BilliumDollars
1BilliumDollars

Reputation: 149

Powershell Select-Object -match or?

Can the select-Object be used like so to match either?

If ((Get-content $file | select-object -last 1) -match 'deleted' -or 'return'){"yes"} else {"No"}

This doesn't produce error but will tell me yes regardless of the last string matched in $file. I would like to do display a Yes if either match.

Upvotes: 4

Views: 9083

Answers (1)

mjolinor
mjolinor

Reputation: 68273

You can use alternation in the regex:

If ((Get-content $file | select-object -last 1) -match 'deleted|return'){"yes"} else {"No"}

Upvotes: 13

Related Questions