I am having issues resolving a revision to the script below. This script will take in a number of key words, either manually added or read from a file. It will output the data when it finds a match by listing the File Name, Line number and the search word. Unfortunately if I'm searching for multiple words it has to scan the files for each separate word. That means if I have 20 search words, it will open, scan, close each file 20 times. Once for each word. Not good as it takes time and I still have to troll through the output to total how many matches per file. Every change I make is disastrous as it prints every single search word without knowing what word was the match or worse it fails to run. Would anyone be able to help me alter the script to scan the files once for ALL the search words and list out only the matches in a readable way like the output below?
$searchWords="Address", "City","State"
Foreach ($sw in $searchWords)
{
Get-Childitem -Path "C:\Workspace\src" -Recurse -include "*.cbl" |
Select-String -Pattern "$sw" |
Select Path,LineNumber,@{n='SearchWord';e={$sw}}
}