0

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.

2

1 Answer 1

0

This may help https://gallery.technet.microsoft.com/office/How-to-search-text-in-e16373b8

Also you may need to loop the folder to search in every excel file

Sign up to request clarification or add additional context in comments.

2 Comments

I used this :$str="26123" GET-CHILDITEM -recurse C:\txt*.txt | SELECT-STRING -pattern "\b$str\b" >>F:\Final.txt Write-Host Done -ForegroundColor Cyan ---------but i first converted xlsx files to txt-tab delimited files
You are welcome :) I followed the link I sent to you and it worked without converting the excel file to txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.