PowerShell: Search for and delete files recursively

Published:

Short and simple, but keep forgetting some minor details, so... note to self...

# Files
gci -recurse -force |
where {$_.name -eq "Thumbs.db"} |
foreach {ri $_.fullname -whatif}

# Directories (and using regex for matching)
gci -recurse -force |
where {$_.name -match "^(bin|obj)$"} |
foreach {ri $_.fullname -recurse -whatif}

Minus the -whatif, of course 🙂