Delete image thumbnails with PowerShell

2016-02-20 | Martin Hoppenheit | 1 min read

Windows Explorer stores image thumbnails in hidden files called Thumbs.db. Suppose you want to clean a large directory tree to keep just the actual image files. That is, you want to delete the Thumbs.db files. But there might be even more (possibly hidden) files or directories you don’t need, like .DS_Store or .picasa.ini files, depending on the image management software used. So prior to just deleting all hidden files, you should do some analysis.

Here are some useful PowerShell commands (where gci is an alias for the Get-ChildItem commandlet).

Show all hidden files in the C:\images directory:

PS> gci C:\images -recurse -hidden

For a quick overview, show only the file names:

PS> gci C:\images -recurse -hidden | select name

Show all hidden files in the C:\images directory that are not named Thumbs.db:

PS> gci C:\images -recurse -hidden | where name -ne 'Thumbs.db'

Delete all hidden files in the C:\images directory:

PS> gci C:\images -recurse -hidden | rm -force

Delete only the Thumbs.db files:

PS> gci C:\images -recurse -hidden -file -filter 'Thumbs.db' | rm -force