Sometimes, we run into a situation where we are looking for certain entries in all files in a directory and withing all the directories. Below is a small code snippet that might help:
# Define the folder path to search
$folderPath = "C:\Path\To\Your\Folder"
# Define the string to search for
$searchString = "your_search_string_here"
# Search for the string in all files recursively
Get-ChildItem -Path $folderPath -Recurse |
Where-Object { !$_.PSIsContainer } |
ForEach-Object {
$filePath = $_.FullName
$content = Get-Content -Path $filePath -Raw
if ($content -match $searchString) {
Write-Output "Found '$searchString' in file: $filePath"
}
}
Thanks!!
No comments:
Post a Comment