param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$directory,
[Parameter(Mandatory = $false, Position = 1)]
[string]$wordFile = "C:\Scripts\files\words.txt"
)
$words = get-content $wordFile
$regex = "(?i)" + ($words -join "\b|") + "\b"
$matched = get-childitem $directory -filter *.txt | get-content | foreach {[regex]::matches($_, $regex)} | %{ $_.Groups[0].Value } | select -Unique
$not_matched = @()
foreach($word in $words)
{
if($matched -notcontains $word)
{ $not_matched += $word }
}
Write-Host "`nSearching all text files found in '$directory' for the words:"
Write-Host "`n$words" -fore cyan
Write-Host "`n`nWords Found" -fore green
Write-Host $matched
Write-Host "`nWords NOT Found" -fore red
Write-Host $not_matched