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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.