Whereis with PowerShell

March 5, 2010

The topic of  “Search function in Vista” was brought up on the Minasi Forum.  (NOTE! if you are not a member you should be)  The DIR /S command was brought up as a replacement option to use since the old method that existed in XP is no longer available.  I remembered reading this article in WIN IT PRO and thought that it may be very useful for what the Admins are trying to accomplish.

You can download the WIN IT Pro Article here Find Files on Local Drives with Whereis and the PS1 code snippet here WhereisPS1 .

Find Files on Local Drives with Whereis.ps1

From the January 2010 Edition
of Windows IT Pro

December 15, 2009
Bill Stewart
Feature
InstantDoc #103096

I often find it useful to search for files from a command line. In the past, I’ve typically used Cmd.exe’s dir command with the /b and /s parameters to search for files; combining these parameters provides a list containing the full paths and filenames of matching files. However, dir doesn’t have a simple syntax for searching multiple locations. For example, to search drives C and D for all files ending in .doc, you would use this command:

dir /b /s c:\*.doc d:\*.doc

The syntax gets even more complex when searching for multiple wildcard patterns (e.g., all .doc, .xls, and .ppt files) in multiple locations because you have to type each location and each wildcard pattern separately.

Windows PowerShell’s Get-ChildItem cmdlet makes this task simpler. For example, to search drives C and D for all .doc, .xls, and .ppt files, you can use this command:

get-childitem c:\*,d:\*
-include *.doc,*.xls,*.ppt -recurse

Get-ChildItem’s first parameter is a list of paths to search, and the -Include parameter specifies a list of wildcard patterns that qualify the paths. The -Recurse parameter is analogous to the dir command’s /s parameter.

Introducing Whereis.ps1

Read the rest of this entry »