Skip to content

Instantly share code, notes, and snippets.

@dalsvk
Last active May 13, 2024 11:08
Show Gist options
  • Save dalsvk/0414b3b161cd5466a6099e2482d61693 to your computer and use it in GitHub Desktop.
Save dalsvk/0414b3b161cd5466a6099e2482d61693 to your computer and use it in GitHub Desktop.
Get-ChildItem -Path $folderPath -File -Recurse | Where-Object { $_.Extension -eq ".html" } | ForEach-Object {
$fileName = $_.Name
$fileCounts = @{}
$content = Get-Content -Path $_.FullName -Raw
foreach ($searchString in $searchStrings) {
$occurrences = ($content | Select-String -Pattern $searchString -AllMatches).Matches.Count
$fileCounts[$searchString] = $occurrences
}
Write-Output "File: $fileName"
foreach ($searchString in $searchStrings) {
if ($fileCounts.ContainsKey($searchString)) {
Write-Output "$searchString : $($fileCounts[$searchString])"
}
}
Write-Output "`n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment