PowerShell – Delete all directories with a given name recursively

 

It turns out to be a bit of a pain to delete all the directories/folders with a certain name.  This’ll do it.

Get-ChildItem C:\path\to\start\directory -Include search1,search2 -Recurse -force | Remove-Item -Recurse -Force

It just gets all the child items in a directory recursively and then removes them.  The -Recurse parameter on the Remove-Item is so that the entire directory and its contents are removed.  search1 and search2 are the the names it is looking for – more or less could be included.

Leave a Reply

Your email address will not be published. Required fields are marked *