This article will explain the PowerShell script that searches for files within document libraries in SharePoint (farm level, site collection level, web level etc.) based on the search parameters you provide. It can also be used for searching in SharePoint for any files with specified extension. The results are returned in .CSV format.SharePoint-2013-Hosting

Examples of scenarios

Search the entire farm for files that have names like “Training Copy”.
Search the site collection http://sharepoint.mydreambox.com/sites/site1 for all PDF files, RDL files, etc.
Search the web http://sharepoint.mydreambox.com/sites/site1/web1 for the file named “AXL8rt.docx”, etc.

Usage of the Script

Replace the $webApp, $sites, etc. with appropriate values
Replace the $searchKey with the desired search queries or file extension that is to be searched for
Make sure the account that is running these scripts have necessary privileges in SharePoint

Script use cases

The code is presented for four different cases,

Searching for an entire farm
Searching within a web application
Searching within a site collection
Searching within a web

Output

The output will be in the form of a CSV file, as displayed below. It will contain all the file location URLs.

Case I – For searching within the entire farm

Case III – For searching within a Site Collection

Case IV – For searching within a Web