1

I'm trying to find all the SQL Server object names (roughly 800) in our source controlled files (1000's.) When I try using Select-String it will find one string but then it stops processing the file on the line it found a match. Here is a small sample of what I'm getting. It should return a match for 'was' as well.

Use the Select-String cmdlet to process both of the words 'test' and 'was' in the same sentence and all it returns is the matches for 'test'.

('This is a test. How was your test?' | Select-String -Pattern @('test','was') -AllMatches).Matches

Groups   : {0}
Success  : True
Name     : 0
Captures : {0}
Index    : 10
Length   : 4
Value    : test

Groups   : {0}
Success  : True
Name     : 0
Captures : {0}
Index    : 29
Length   : 4
Value    : test
runamuk0
  • 784
  • 1
  • 7
  • 20

1 Answers1

1

You can accomplish this by using a regular expression instead of an array of strings:

('This is a test. How was your test?' | Select-String -Pattern '\btest\b|\bwas\b' -AllMatches).Matches
Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35