Searching through Excel files for a string using PowerShell

This morning I had to find an Excel file with a certain text in it. Here’s a working example of how I did it that you can execute in Powershell.

Copy and paste the above function into PowerShell.

The following is an example for searching the entire C:\drive for file extensions .xls, .xlsx, .xlsm for the search term MyText.

Get-ChildItem -Path "C:\*" -Recurse -Include *.xls, *.xlsx, *.xlsm | Select-Object -Property Directory, Name | ForEach-Object { "{0}\{1}" -f $_.Directory, $_.Name } | Search-Excel -SearchText MyText

I haven’t been able to figure out how we can do search strings with spaces such as My Text. The search text can accept wildcard characters such as * and ? . If you have any ideas on how we can do that, please leave a comment.

Before you go

Follow me on Twitter, where I regularly tweet about Technology and Business.

Personal growth, technology and business @ https://me.shuaib.org