The following powershell script searches in the specified folder ($folder) and filters for a file extension if parameter ($extension).
The script will echo the filename and delete
$folder = "C:\Users"
$extension = "cmd"
if (!($extension)){$filter="*"}
Else{$filter=foreach ($item in $extension.split(",")){$item.insert(0,"*.")}}
if (test-path $folder) {
foreach ($file in get-childitem "$folder\*" -recurse -force -include $filter){
write-host "Deleting file: $($file.fullname)"
remove-item -literalPath $file.fullname -force
} #end foreach
}#end if
Make sure to test the script before using it in production and distributing it

Leave a comment