Search files content fast in powershell I need to search a large repository of files for a specific resource, and return it only if it is used or not. 

It is working as expected, but it is very time consuming. To search for 50 resource names takes around 200 seconds. I have many more than 50. 

I found this question that helped a bit, but I was wondering if there is anything else I can do to speed it up. 

$searchList = Get-ChildItem -r *.cs -OutBuffer 1000000
$usedIcons = @()

foreach ($name in $testNames) {
    $pattern = "Resources."+$name
    $found = $searchList | Select-String -Pattern $pattern -SimpleMatch -Quiet
    if($found -eq $true){
        Write-Host $name 
        $usedIcons += $name
    }
}
I also suggest to use a better RegEx but stay with PowerShell.

Without exactly knowing your $testnames you can manually or automatically build a RegEx with a lookbehind and alternations and read the *.cs files only once.

## build some sample files 
'foo','bar','baz'|ForEach-Object{"Resources.$_" &gt; "$_.cs"}

$testnames = [RegEx]"(?&lt;=Resources\.)(foo|bar|baz)"
# (zero length look behind assertion)(alternation)

$Result =  Get-ChildItem *.cs -Recurse -File | 
  Select-String -Pattern $testnames|
    Select-Object @{n='UsedIcons';e={$_.Matches.Groups[0].Value}} -Unique

$Result


Sample output:

UsedIcons
---------
bar
baz
foo