PowerShell: Quick Way to Check for a File Type on a Drive or Directory

Posted June 7, 2007 by Rob Rogers in Windows

Instead of performing a search on a drive or directory to see if files of a specific file type reside on it, you can save a lot of time by using PowerShell. It will come back with a True or False response in a matter of seconds instead of having to wait for the search to complete. This comes in handy if you are trying to analyze what file types are being stored on your server (for example, you want to make sure no one is stashing their MP3 collection on it!)


1. Open PowerShell.

2. You will use the test-path cmdlet, the directory or drive path, and a wildcard expression, so if we were checking the Data directory on the C Drive for MP3 files, it would look like this:test-path C:\Data\*.mp3

3. Press Enter.

4. You will receive either a True or False response.

 

About Rob Rogers

Once a prolific author here on Tech-Recipes, Rob has moved on to greener pastures.
View more articles by Rob Rogers

The Conversation

Follow the reactions below and share your own thoughts.