PowerShell: Searching text string on files.

 

 

1. Looking for string "janice" and create an output file as "output.txt"

dir C:\MyFolder I *.txt -R | Select-String -Pattern janice > C:\MyFolder\output.txt

  

2. Looking for string "janice" and "john" and create an output file as "output.txt"

dir C:\MyFolder I *.txt -R | Select-String -Pattern janice, john > C:\MyFolder\output.txt

 

 

3. Looking for string "connection error" and create an output file as "output.txt"

dir C:\MyFolder I *.txt -R | Select-String -Pattern "connection error" > C:\MyFolder\output.txt

 

4. Looking for string "janice" and "john" from two different file extension. Then creating an output file as "output.txt"

dir C:\MyFolder I *.txt,*.log -R | Select-String -Pattern janice,john > C:\MyFolder\output.txt

Leave a Reply