troubleshooting Question

Select-String powershell advice

Avatar of Pau Lo
Pau Lo asked on
Scripting LanguagesPowershell
1 Comment1 Solution130 ViewsLast Modified:
I found a usefulPowerShell script online (full code below) which helped me review an enormous txt file (log file) for rows containing a key word phrase and output just those rows to a txt file. What I could do with is a way of amending the $pattern row below:

$pattern = ‘searchterm’ search another text file I have created which contains for a number of search terms I have put together, rather than me having to run the command for every search phrase I need to check individually.

full code:

$inFile = '\\server\share\directoruy\file.txt'
$outFile = '\\server\share\directoruy\hits.txt'
$pattern = ‘searchterm’
Select-String -Path $inFile -SimpleMatch $pattern | Select-Object -ExpandProperty Line | Set-Content -Path $outFile

for info the format of the text file I have created for using is just in a row by row format, e.g

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros