Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Select-Object -match or?

Tags:

powershell

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.

like image 935
1BilliumDollars Avatar asked Dec 20 '22 21:12

1BilliumDollars


1 Answers

You can use alternation in the regex:

If ((Get-content $file | select-object -last 1) -match 'deleted|return'){"yes"} else {"No"}
like image 155
mjolinor Avatar answered Jan 17 '23 15:01

mjolinor