
Use Select-String in Windows PowerShell when you need to find a word or pattern across several text files without opening them individually.
Search multiple text files
For example, to find the text ayam in the DEFAULT1.txt through DEFAULT5.txt files under C:\ITsiti, use the following command. Adjust the path and search text for your environment.
Select-String -Path 'C:\ITsiti\DEFAULT*.txt' -Pattern 'ayam' -SimpleMatchThe result includes the path, line number and matching line. In the original example, the matches were:
DEFAULT1.txt:18:ayam_kampung
DEFAULT2.txt:10:ayam
DEFAULT5.txt:27:ayam_bandarSearch within subfolders
Get-ChildItem -Path 'C:\ITsiti' -Filter '*.txt' -File -Recurse |
Select-String -Pattern 'ayam' -SimpleMatchUse -SimpleMatch for literal text. Without it, the pattern is interpreted as a regular expression. Select-String is suitable for plain text files; it is not a parser for binary Word or PDF documents. Limit the search to authorized folders, especially when looking through application logs.
