Saturday, June 30, 2018

Use PowerShell to Search Text Files for Strings

PowerShell can quickly search text files for a string of characters:

Select-String -Path .\servers.txt -Pattern "abc"

 


For this example, we used Select-String to search a list of server names in a text file called 'servers.txt', then used the -Pattern parameter to designate the string we're looking for.

PowerShell returned the filename, the line number where the pattern was found, and the full line. 

Note: case is not sensitive here. A search for "ABC" will return the same result. 
 

No comments:

Post a Comment