I have a folder containing multiple excel files. I want to search for a string like "2501" and find which of my files contains this string then output it's file name to a file (or display it). I wrote some scripts and googled but did not find the answer.
I wrote this :
$Location = "C:\1.xlsx"
$SearchStr = "Mike"
$Sel = Select-String -pattern $SearchStr -path $Location
If ($Sel -eq $null)
{
write-host "$Location does not contain $SearchStr" -ForegroundColor Cyan
}
Else
{
write-host "Found $SearchStr `n$Se in $Location"
}
Write-host "end" -ForegroundColor Yellow
This works only if I specify a txt file, it does not work with Excel.