Category:Automation -> PowerShell
This is a PowerShell script I developed which will scan all files in /Configs/ folder for anything that will match the search string. It will then create a .txt file in the same directory with the script to save search results into. Create /Configs/ folder and copy your files into it. As is the script will run through files with .log extension ONLY but can be modified to match any file type.
Should help and save time in troubleshooting and running through hundreds of files in search for a specific object. Use your imagination for you can supply anything to run through and find in seconds.
<#
.SYNOPSIS
Run search through files for any txt string and save results
.DESCRIPTION
This script looks inside /Config/ directory and scans all files with .log extension for requested text string.
It then creates and saves results into Config_Search_Results.txt file.
.NOTES
File Name : Config_Search_v2
Author : privilege15
Requires : PowerShell
.LINK
http://evilttl.com/
#>
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$searchresultspath = $directorypath + '\Config_Search_Results.txt'
$configpath = $directorypath + '\Configs\'
# Set max width for Out-File to avoid text wrapping
$PSDefaultParameterValues=@{"Out-File:Width"="10000"}
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $searchresultspath
Set-location $configpath
$String = Read-Host -Prompt 'Input your search string'
Write-Output 'Processing...'
Get-ChildItem . -r *.log | Select-String -pattern $String -list |
Format-Table Filename
Stop-Transcript
#$File = Read-Host -Prompt 'Input filename to search for the string inside'
#Select-String -Path $configpath$File -Pattern $String
Read-Host -Prompt "`r`nScan files above and save results to 'Config_Search_Results.txt'? Press Enter to continue"
Write-Output 'Scanning and saving to file... Please await until prompt pops up'
Select-String -Path $Path*.log -Pattern $String | Out-File -FilePath $searchresultspath -append
Read-Host -Prompt "`r`nResults saved into Config_Search_Results.txt. Press Enter to exit"