Search file structure for a file or file type and put the results in a CSV file (Powershell)

*** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***

I put this script together to search my SAN for some files we didn’t want taking up space on our device. It’s essentially a re-work of this script (http://www.signalwarrant.com/2012/07/31/search-for-specific-file-extension-powershell/) from a few months ago.

It’s pretty simple to use; once you execute the script in the shell it will prompt you for the directory to search. The directory can be in the form of C:\files or \\server\share, either one will work provided you have the proper permissions to the files.

Next, you will be prompted for the file or file type you want to search for; for example file.txt or for all .txt files use *.txt.

Once the search is complete it will save the results in a CSV file and open the file in excel for you.

Why use this over the built in windows search? I think it’s faster and in my case I needed to weed through the results to see exactly which files I wanted to delete, the CSV file makes that easy.

 

1 Comment

Leave a Reply