Powershell – Find files across all drives using Powershell

powershell

I know how to search for files using dir/gci, but that only works across one drive AFAIK.

  • Is there a way to search across all drives on the computer?
  • Is there a way without manually enumerating then looping through the drives?
  • Is there a way to access the search indexes/services that are already available in windows, to speed up the search?

Best Answer

This will list all ZIP files in decending size order by directory on all available drives:

get-psdrive -p "FileSystem" `
| % {write-host -f Green "Searching " $_.Root;get-childitem $_.Root -include *.ZIP -r `
| sort-object Length -descending}

Or search a specified list of Drives/Shares (e.g. C:, D: and \SERVER1\SHARE1...)

$paths="C:\","D:\","\\SERVER1\SHARE1" `
| % {write-host -f Green "Searching " $_;get-childitem $_ -include *.ZIP -r `
| sort-object Length -descending}
Related Topic